diff --git a/castor/db/oracleCommon.schema.sql b/castor/db/oracleCommon.schema.sql index 4f9c67188be1a3c53b92bb7721814f954b3eaebc..4274b31d8040d72e7128ddb4ae81841414231452 100644 --- a/castor/db/oracleCommon.schema.sql +++ b/castor/db/oracleCommon.schema.sql @@ -10,6 +10,30 @@ /* SQL statement to populate the intial schema version */ UPDATE UpgradeLog SET schemaVersion = '2_1_13_0'; +/* Get current time as a time_t. Not that easy in ORACLE */ +CREATE OR REPLACE FUNCTION getTime RETURN NUMBER IS + epoch TIMESTAMP WITH TIME ZONE; + now TIMESTAMP WITH TIME ZONE; + interval INTERVAL DAY(9) TO SECOND; + interval_days NUMBER; + interval_hours NUMBER; + interval_minutes NUMBER; + interval_seconds NUMBER; +BEGIN + epoch := TO_TIMESTAMP_TZ('01-JAN-1970 00:00:00 00:00', + 'DD-MON-YYYY HH24:MI:SS TZH:TZM'); + now := SYSTIMESTAMP AT TIME ZONE '00:00'; + interval := now - epoch; + interval_days := EXTRACT(DAY FROM (interval)); + interval_hours := EXTRACT(HOUR FROM (interval)); + interval_minutes := EXTRACT(MINUTE FROM (interval)); + interval_seconds := EXTRACT(SECOND FROM (interval)); + + RETURN interval_days * 24 * 60 * 60 + interval_hours * 60 * 60 + + interval_minutes * 60 + interval_seconds; +END; +/ + /* Sequence for indices */ CREATE SEQUENCE ids_seq CACHE 300; @@ -151,6 +175,14 @@ CREATE TABLE RecallGroup(id INTEGER CONSTRAINT PK_RecallGroup_Id PRIMARY KEY CON lastEditionTime NUMBER CONSTRAINT NN_RecallGroup_LastEdTime NOT NULL) INITRANS 50 PCTFREE 50 ENABLE ROW MOVEMENT; +/* Insert the bare minimum to get a working recall: + * create the default recall group to have a default recall mount traffic shaping. + */ +INSERT INTO RecallGroup (id, name, nbDrives, minAmountDataForMount, minNbFilesForMount, + maxFileAgeBeforeMount, vdqmPriority, lastEditor, lastEditionTime) + VALUES (ids_seq.nextval, 'default', 20, 10*1024*1024*1024, 10, 30*3600, 0, '', getTime()); + + /* Definition of the RecallUser table * euid : uid of the recall user * egid : gid of the recall user @@ -749,7 +781,6 @@ COMMIT; /* when they change status */ /*********************************************************************/ CREATE TABLE FileSystemsToCheck (FileSystem NUMBER CONSTRAINT PK_FSToCheck_FS PRIMARY KEY, ToBeChecked NUMBER); -INSERT INTO FileSystemsToCheck SELECT id, 0 FROM FileSystem; /**************/ diff --git a/castor/db/oracleCommon.sql b/castor/db/oracleCommon.sql index 6f738851c0c748361fa1941f9ff516dc1bf47204..8139964c581b9991b35768c8bf2d92609962e38d 100644 --- a/castor/db/oracleCommon.sql +++ b/castor/db/oracleCommon.sql @@ -7,30 +7,6 @@ * @author Castor Dev team, castor-dev@cern.ch *******************************************************************/ -/* Get current time as a time_t. Not that easy in ORACLE */ -CREATE OR REPLACE FUNCTION getTime RETURN NUMBER IS - epoch TIMESTAMP WITH TIME ZONE; - now TIMESTAMP WITH TIME ZONE; - interval INTERVAL DAY(9) TO SECOND; - interval_days NUMBER; - interval_hours NUMBER; - interval_minutes NUMBER; - interval_seconds NUMBER; -BEGIN - epoch := TO_TIMESTAMP_TZ('01-JAN-1970 00:00:00 00:00', - 'DD-MON-YYYY HH24:MI:SS TZH:TZM'); - now := SYSTIMESTAMP AT TIME ZONE '00:00'; - interval := now - epoch; - interval_days := EXTRACT(DAY FROM (interval)); - interval_hours := EXTRACT(HOUR FROM (interval)); - interval_minutes := EXTRACT(MINUTE FROM (interval)); - interval_seconds := EXTRACT(SECOND FROM (interval)); - - RETURN interval_days * 24 * 60 * 60 + interval_hours * 60 * 60 + - interval_minutes * 60 + interval_seconds; -END; -/ - /* Returns a time interval in seconds */ CREATE OR REPLACE FUNCTION getSecs(startTime IN TIMESTAMP, endTime IN TIMESTAMP) RETURN NUMBER IS BEGIN diff --git a/castor/db/oracleTapeGateway.sql b/castor/db/oracleTapeGateway.sql index abebd5c6350cf3ebbbee70b9b65253167d7da6a7..86d8024b1a4638f519d5d099ea9020080725ba76 100644 --- a/castor/db/oracleTapeGateway.sql +++ b/castor/db/oracleTapeGateway.sql @@ -1579,13 +1579,3 @@ BEGIN COMMENTS => 'Creates RecallMount entries when new recalls should start'); END; / - - -/* Insert the bare minimum to get a working system. Inserted late in the creation - * script in order to use getTime(). - * - Create the default recall group to have a default recall mount traffic shaping. - */ -INSERT INTO RecallGroup (id, name, nbDrives, minAmountDataForMount, minNbFilesForMount, maxFileAgeBeforeMount, vdqmPriority, lastEditor, lastEditionTime) -VALUES (ids_seq.nextval, 'default', 20, 10*1024*1024*1024, 10, 30*3600, 0, '2.1.13 upgrade script', getTime()); - -/* End of oracleTapeGateway.sql. This trailer makes sure the previous statement is followed by a new line. */ diff --git a/ns/oracleSchema.sql b/ns/oracleSchema.sql index a5791bf348099cde0195a0fe9f68cfabdf3cec95..fb1f86bb54ea9d76b8a4c6974e89518c334b7b88 100644 --- a/ns/oracleSchema.sql +++ b/ns/oracleSchema.sql @@ -97,6 +97,13 @@ CREATE INDEX I_seg_metadata_tapesum ON Cns_seg_metadata (vid, s_fileid, segsize, CREATE GLOBAL TEMPORARY TABLE Cns_files_exist_tmp (tmpFileId NUMBER) ON COMMIT DELETE ROWS; +-- A synonym allowing to acces the VMGR_TAPE_SIDE table from within the nameserver DB. +-- Note that the VMGR schema shall grant read access to the NS account with something like: +-- GRANT SELECT ON Vmgr_Tape_Side TO <CastorNsAccount>; +UNDEF vmgrSchema +ACCEPT vmgrSchema CHAR DEFAULT 'castor_vmgr' PROMPT 'Enter the name of the VMGR schema (default castor_vmgr): '; +CREATE OR REPLACE SYNONYM Vmgr_tape_side FOR &vmgrSchema..Vmgr_tape_side; + -- Tables to store intermediate data to be passed from/to the stager. -- Note that we cannot use temporary tables with distributed transactions. CREATE TABLE SetSegmentsForFilesHelper @@ -105,3 +112,15 @@ CREATE TABLE SetSegmentsForFilesHelper CREATE TABLE ResultsLogHelper (reqId VARCHAR2(36), timeinfo NUMBER, ec INTEGER, fileId NUMBER, msg VARCHAR2(2048), params VARCHAR2(4000)); + +/* Insert the bare minimum to get a working system. + * - Create a default 'system' fileclass. Pre-requisite to next step. + * - Create the root directory. + */ +INSERT INTO cns_class_metadata (classid, name, owner_uid, gid, min_filesize, max_filesize, flags, maxdrives, + max_segsize, migr_time_interval, mintime_beforemigr, nbcopies, retenp_on_disk) + VALUES (1, 'system', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); +INSERT INTO cns_file_metadata (fileid, parent_fileid, guid, name, filemode, nlink, owner_uid, gid, filesize, + atime, mtime, ctime, fileclass, status, csumtype, csumvalue, acl) + VALUES (2, 0, NULL, '/', 16877, 0, 0, 0, 0, 0, 0, 0, 1, '-', NULL, NULL, NULL); +COMMIT; diff --git a/ns/oracleTrailer.sql b/ns/oracleTrailer.sql index 724b84bf60fe1006919d1fb662c19fa2614965a5..b0c0ae5d189bb10ed87aee712b191a18f0cc8b25 100644 --- a/ns/oracleTrailer.sql +++ b/ns/oracleTrailer.sql @@ -541,20 +541,3 @@ BEGIN COMMIT; END; / -/* Insert the bare minimum to get a working system. Inserted late in the creation - * script in order to use getTime(). - * - Create a default 'system' fileclass. Pre-requisite to next step. - * - Create the root directory. - * - Create a synonym to access the VMGR. This requires CNS and VMGR co-location - * in the same database. - */ --- Root entry - insert into cns_class_metadata (classid, name, owner_uid, gid, min_filesize, max_filesize, flags, maxdrives, max_segsize, migr_time_interval, mintime_beforemigr, nbcopies, retenp_on_disk) -values ( 1, 'system', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); -insert into cns_file_metadata (fileid, parent_fileid, guid, name, filemode, nlink, owner_uid, gid, filesize, atime, mtime, ctime, fileclass, status, csumtype, csumvalue, acl) -values ( 2, 0, NULL, '/', 16877, 0, 0, 0, 0, getTime(), getTime(), getTime(), 1, '-', NULL, NULL, NULL); - --- A synonym allowing to acces the VMGR_TAPE_SIDE table from within the nameserver DB -UNDEF vmgrSchema -ACCEPT vmgrSchema CHAR DEFAULT 'vmgr' PROMPT 'Enter the name of the VMGR schema (default vmgr): '; -CREATE OR REPLACE SYNONYM Vmgr_tape_side FOR &vmgrSchema..Vmgr_tape_side; \ No newline at end of file