From 56f21908ebc2b9b0f825a7302e23ab30ede214cb Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Sat, 16 Apr 2011 08:44:53 +0200 Subject: [PATCH] Update Catalog version and use DeltaSeq instead of MarkId --- bacula/src/cats/cats.h | 3 ++- bacula/src/cats/dbi.c | 4 +-- bacula/src/cats/ingres.c | 2 +- bacula/src/cats/make_mysql_tables.in | 1 + bacula/src/cats/make_postgresql_tables.in | 1 + bacula/src/cats/make_sqlite3_tables.in | 1 + bacula/src/cats/mysql.c | 2 +- bacula/src/cats/postgresql.c | 14 +++++------ bacula/src/cats/sql_cmds.c | 28 ++++++++++----------- bacula/src/cats/sql_create.c | 6 ++--- bacula/src/cats/sql_get.c | 4 +-- bacula/src/cats/sqlite.c | 2 +- bacula/src/cats/update_mysql_tables.in | 4 ++- bacula/src/cats/update_postgresql_tables.in | 4 ++- bacula/src/cats/update_sqlite3_tables.in | 4 ++- bacula/src/dird/backup.c | 2 +- bacula/src/dird/ua_tree.c | 2 +- 17 files changed, 47 insertions(+), 37 deletions(-) diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index b7b13e9c72..e83287a560 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -213,6 +213,7 @@ struct FILE_DBR { DBId_t FilenameId; DBId_t PathId; JobId_t MarkId; + uint32_t DeltaSeq; char LStat[256]; char Digest[BASE64_SIZE(CRYPTO_DIGEST_MAX_SIZE)]; int DigestType; /* NO_SIG/MD5_SIG/SHA1_SIG */ @@ -437,7 +438,7 @@ typedef int (DB_RESULT_HANDLER)(void *, int, char **); #define db_unlock(mdb) mdb->_db_unlock(__FILE__, __LINE__) /* Current database version number for all drivers */ -#define BDB_VERSION 13 +#define BDB_VERSION 14 class B_DB: public SMARTALLOC { protected: diff --git a/bacula/src/cats/dbi.c b/bacula/src/cats/dbi.c index dc88bfed4a..714efcc96c 100644 --- a/bacula/src/cats/dbi.c +++ b/bacula/src/cats/dbi.c @@ -1187,7 +1187,7 @@ bool B_DB_DBI::sql_batch_start(JCR *jcr) "Name blob," "LStat tinyblob," "MD5 tinyblob," - "MarkId integer)")) { + "DeltaSeq smallint)")) { Dmsg0(500, "sql_batch_start failed\n"); goto bail_out; } @@ -1252,7 +1252,7 @@ bool B_DB_DBI::sql_batch_start(JCR *jcr) "Name blob," "LStat tinyblob," "MD5 tinyblob," - "MarkId integer)")) { + "DeltaSeq smallint)")) { Dmsg0(500, "sql_batch_start failed\n"); goto bail_out; } diff --git a/bacula/src/cats/ingres.c b/bacula/src/cats/ingres.c index 1e1e6742e2..0cc52a16f8 100755 --- a/bacula/src/cats/ingres.c +++ b/bacula/src/cats/ingres.c @@ -1014,7 +1014,7 @@ bool B_DB_INGRES::sql_batch_start(JCR *jcr) "Name VARBYTE(32000)," "LStat VARBYTE(255)," "MD5 VARBYTE(255)," - "MarkId INTEGER)" + "DeltaSeq SMALLINT)" " ON COMMIT PRESERVE ROWS WITH NORECOVERY"); db_unlock(this); return ok; diff --git a/bacula/src/cats/make_mysql_tables.in b/bacula/src/cats/make_mysql_tables.in index 2a5b6889ff..acced10eee 100644 --- a/bacula/src/cats/make_mysql_tables.in +++ b/bacula/src/cats/make_mysql_tables.in @@ -52,6 +52,7 @@ CREATE TABLE File ( JobId INTEGER UNSIGNED NOT NULL REFERENCES Job, PathId INTEGER UNSIGNED NOT NULL REFERENCES Path, FilenameId INTEGER UNSIGNED NOT NULL REFERENCES Filename, + DeltaSeq SMALLINT UNSIGNED DEFAULT 0, MarkId INTEGER UNSIGNED DEFAULT 0, LStat TINYBLOB NOT NULL, MD5 TINYBLOB, diff --git a/bacula/src/cats/make_postgresql_tables.in b/bacula/src/cats/make_postgresql_tables.in index 0bb7bfa00c..cb8d58dd6d 100644 --- a/bacula/src/cats/make_postgresql_tables.in +++ b/bacula/src/cats/make_postgresql_tables.in @@ -53,6 +53,7 @@ CREATE TABLE File JobId integer not null, PathId integer not null, FilenameId integer not null, + DeltaSeq smallint not null default 0, MarkId integer not null default 0, LStat text not null, Md5 text not null, diff --git a/bacula/src/cats/make_sqlite3_tables.in b/bacula/src/cats/make_sqlite3_tables.in index e32bc05cd5..648993882e 100644 --- a/bacula/src/cats/make_sqlite3_tables.in +++ b/bacula/src/cats/make_sqlite3_tables.in @@ -33,6 +33,7 @@ CREATE TABLE File ( JobId INTEGER UNSIGNED REFERENCES Job NOT NULL, PathId INTEGER UNSIGNED REFERENCES Path NOT NULL, FilenameId INTEGER UNSIGNED REFERENCES Filename NOT NULL, + DeltaSeq SMALLINT UNSIGNED DEFAULT 0, MarkId INTEGER UNSIGNED DEFAULT 0, LStat VARCHAR(255) NOT NULL, MD5 VARCHAR(255) NOT NULL, diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index bc8b3b14b9..4c5bbfbd97 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -578,7 +578,7 @@ bool B_DB_MYSQL::sql_batch_start(JCR *jcr) "Name blob," "LStat tinyblob," "MD5 tinyblob," - "MarkId integer)"); + "DeltaSeq integer)"); db_unlock(this); return retval; diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index 0e17372783..924b7548f9 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -938,13 +938,13 @@ bool B_DB_POSTGRESQL::sql_batch_start(JCR *jcr) Dmsg0(500, "sql_batch_start started\n"); if (!sql_query("CREATE TEMPORARY TABLE batch (" - "fileindex int," - "jobid int," - "path varchar," - "name varchar," - "lstat varchar," - "md5 varchar," - "markid int)")) { + "FileIndex int," + "JobId int," + "Path varchar," + "Name varchar," + "LStat varchar," + "Md5 varchar," + "DeltaSeq smallint)")) { Dmsg0(500, "sql_batch_start failed\n"); return false; } diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c index 0327e4bfd5..3c91aa449c 100644 --- a/bacula/src/cats/sql_cmds.c +++ b/bacula/src/cats/sql_cmds.c @@ -263,7 +263,7 @@ const char *uar_jobid_fileindex_from_table = */ const char *select_recent_version_with_basejob_default = "SELECT FileId, Job.JobId AS JobId, FileIndex, File.PathId AS PathId, " - "File.FilenameId AS FilenameId, LStat, MD5, MarkId, " + "File.FilenameId AS FilenameId, LStat, MD5, DeltaSeq, " "Job.JobTDate AS JobTDate " "FROM Job, File, ( " "SELECT MAX(JobTDate) AS JobTDate, PathId, FilenameId " @@ -294,13 +294,13 @@ const char *select_recent_version_with_basejob[] = { /* Postgresql */ /* The DISTINCT ON () permits to avoid extra join */ "SELECT DISTINCT ON (FilenameId, PathId) JobTDate, JobId, FileId, " - "FileIndex, PathId, FilenameId, LStat, MD5, MarkId " + "FileIndex, PathId, FilenameId, LStat, MD5, DeltaSeq " "FROM " - "(SELECT FileId, JobId, PathId, FilenameId, FileIndex, LStat, MD5, MarkId " + "(SELECT FileId, JobId, PathId, FilenameId, FileIndex, LStat, MD5, DeltaSeq " "FROM File WHERE JobId IN (%s) " "UNION ALL " "SELECT File.FileId, File.JobId, PathId, FilenameId, " - "File.FileIndex, LStat, MD5, MarkId " + "File.FileIndex, LStat, MD5, DeltaSeq " "FROM BaseFiles JOIN File USING (FileId) " "WHERE BaseFiles.JobId IN (%s) " ") AS T JOIN Job USING (JobId) " @@ -330,22 +330,22 @@ const char *select_recent_version_with_basejob[] = { */ const char *select_recent_version_with_basejob_and_delta_default = "SELECT FileId, Job.JobId AS JobId, FileIndex, File.PathId AS PathId, " - "File.FilenameId AS FilenameId, LStat, MD5, File.MarkId AS MarkId, " + "File.FilenameId AS FilenameId, LStat, MD5, File.DeltaSeq AS DeltaSeq, " "Job.JobTDate AS JobTDate " "FROM Job, File, ( " - "SELECT MAX(JobTDate) AS JobTDate, PathId, FilenameId, MarkId " + "SELECT MAX(JobTDate) AS JobTDate, PathId, FilenameId, DeltaSeq " "FROM ( " - "SELECT JobTDate, PathId, FilenameId, MarkId " /* Get all normal files */ + "SELECT JobTDate, PathId, FilenameId, DeltaSeq " /*Get all normal files*/ "FROM File JOIN Job USING (JobId) " /* from selected backup */ "WHERE File.JobId IN (%s) " "UNION ALL " - "SELECT JobTDate, PathId, FilenameId, MarkId " /* Get all files from */ + "SELECT JobTDate, PathId, FilenameId, DeltaSeq " /*Get all files from */ "FROM BaseFiles " /* BaseJob */ "JOIN File USING (FileId) " "JOIN Job ON (BaseJobId = Job.JobId) " "WHERE BaseFiles.JobId IN (%s) " /* Use Max(JobTDate) to find */ ") AS tmp " - "GROUP BY PathId, FilenameId, MarkId " /* the latest file version */ + "GROUP BY PathId, FilenameId, DeltaSeq " /* the latest file version */ ") AS T1 " "WHERE (Job.JobId IN ( " /* Security, we force JobId to be valid */ "SELECT DISTINCT BaseJobId FROM BaseFiles WHERE JobId IN (%s)) " @@ -360,18 +360,18 @@ const char *select_recent_version_with_basejob_and_delta[] = { select_recent_version_with_basejob_and_delta_default, /* Postgresql */ /* The DISTINCT ON () permits to avoid extra join */ - "SELECT DISTINCT ON (FilenameId, PathId, MarkId) JobTDate, JobId, FileId, " - "FileIndex, PathId, FilenameId, LStat, MD5, MarkId " + "SELECT DISTINCT ON (FilenameId, PathId, DeltaSeq) JobTDate, JobId, FileId, " + "FileIndex, PathId, FilenameId, LStat, MD5, DeltaSeq " "FROM " - "(SELECT FileId, JobId, PathId, FilenameId, FileIndex, LStat, MD5, MarkId " + "(SELECT FileId, JobId, PathId, FilenameId, FileIndex, LStat, MD5,DeltaSeq " "FROM File WHERE JobId IN (%s) " "UNION ALL " "SELECT File.FileId, File.JobId, PathId, FilenameId, " - "File.FileIndex, LStat, MD5, MarkId " + "File.FileIndex, LStat, MD5, DeltaSeq " "FROM BaseFiles JOIN File USING (FileId) " "WHERE BaseFiles.JobId IN (%s) " ") AS T JOIN Job USING (JobId) " - "ORDER BY FilenameId, PathId, MarkId, JobTDate DESC ", + "ORDER BY FilenameId, PathId, DeltaSeq, JobTDate DESC ", /* SQLite3 */ select_recent_version_with_basejob_and_delta_default, diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index e281548c7a..5c8ec87dde 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -849,9 +849,9 @@ bool db_write_batch_file_records(JCR *jcr) } if (!db_sql_query(jcr->db_batch, - "INSERT INTO File (FileIndex, JobId, PathId, FilenameId, LStat, MD5, MarkId) " +"INSERT INTO File (FileIndex, JobId, PathId, FilenameId, LStat, MD5, DeltaSeq) " "SELECT batch.FileIndex, batch.JobId, Path.PathId, " - "Filename.FilenameId,batch.LStat, batch.MD5, batch.MarkId " + "Filename.FilenameId,batch.LStat, batch.MD5, batch.DeltaSeq " "FROM batch " "JOIN Path ON (batch.Path = Path.Path) " "JOIN Filename ON (batch.Name = Filename.Name)", @@ -985,7 +985,7 @@ static int db_create_file_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) /* Must create it */ Mmsg(mdb->cmd, "INSERT INTO File (FileIndex,JobId,PathId,FilenameId," - "LStat,MD5,MarkId) VALUES (%u,%u,%u,%u,'%s','%s',%u)", + "LStat,MD5,DeltaSeq) VALUES (%u,%u,%u,%u,'%s','%s',%u)", ar->FileIndex, ar->JobId, ar->PathId, ar->FilenameId, ar->attr, digest, ar->DeltaSeq); diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 4fd49c5a91..7e4960eed7 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1155,7 +1155,7 @@ bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, * or Migration */ Mmsg(buf, -"SELECT Path.Path, Filename.Name, T1.FileIndex, T1.JobId, LStat, MarkId, MD5 " +"SELECT Path.Path, Filename.Name, T1.FileIndex, T1.JobId, LStat, DeltaSeq, MD5 " "FROM ( %s ) AS T1 " "JOIN Filename ON (Filename.FilenameId = T1.FilenameId) " "JOIN Path ON (Path.PathId = T1.PathId) " @@ -1286,7 +1286,7 @@ bool db_get_base_file_list(JCR *jcr, B_DB *mdb, bool use_md5, POOL_MEM buf(PM_MESSAGE); Mmsg(buf, - "SELECT Path, Name, FileIndex, JobId, LStat, 0 As MarkId, MD5 " + "SELECT Path, Name, FileIndex, JobId, LStat, 0 As DeltaSeq, MD5 " "FROM new_basefile%lld ORDER BY JobId, FileIndex ASC", (uint64_t) jcr->JobId); diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index d26632c53c..5a7f016d0e 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -666,7 +666,7 @@ bool B_DB_SQLITE::sql_batch_start(JCR *jcr) "Name blob," "LStat tinyblob," "MD5 tinyblob," - "MarkId integer)"); + "DeltaSeq integer)"); db_unlock(this); return retval; diff --git a/bacula/src/cats/update_mysql_tables.in b/bacula/src/cats/update_mysql_tables.in index db3fd19d00..95783906af 100644 --- a/bacula/src/cats/update_mysql_tables.in +++ b/bacula/src/cats/update_mysql_tables.in @@ -44,8 +44,10 @@ CREATE TABLE RestoreObject ( CREATE INDEX jobhisto_jobid_idx ON JobHisto (JobId); +ALTER TABLE File ADD COLUMN DeltaSeq smallint default 0; + DELETE FROM Version; -INSERT INTO Version (VersionId) VALUES (13); +INSERT INTO Version (VersionId) VALUES (14); END-OF-DATA then diff --git a/bacula/src/cats/update_postgresql_tables.in b/bacula/src/cats/update_postgresql_tables.in index c21729a51a..cbc51850d3 100644 --- a/bacula/src/cats/update_postgresql_tables.in +++ b/bacula/src/cats/update_postgresql_tables.in @@ -41,7 +41,9 @@ CREATE TABLE RestoreObject ( ); CREATE INDEX restore_jobid_idx on RestoreObject(JobId); -UPDATE Version SET VersionId=13; +ALTER TABLE File ADD COLUMN DeltaSeq smallint default 0; + +UPDATE Version SET VersionId=14; COMMIT; ANALYSE; diff --git a/bacula/src/cats/update_sqlite3_tables.in b/bacula/src/cats/update_sqlite3_tables.in index 968879ad06..1b8ae4f67b 100644 --- a/bacula/src/cats/update_sqlite3_tables.in +++ b/bacula/src/cats/update_sqlite3_tables.in @@ -46,7 +46,9 @@ CREATE TABLE RestoreObject ( ); CREATE INDEX restore_jobid_idx ON RestoreObject (JobId); -UPDATE Version SET VersionId=13; +ALTER TABLE File ADD COLUMN DeltaSeq smallint default 0; + +UPDATE Version SET VersionId=14; COMMIT; END-OF-DATA diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 69b6a8de38..f5a1fe4f61 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -138,7 +138,7 @@ static bool get_base_jobids(JCR *jcr, db_list_ctx *jobids) /* * Foreach files in currrent list, send "/path/fname\0LStat\0MD5\0Delta" to FD * row[0]=Path, row[1]=Filename, row[2]=FileIndex - * row[3]=JobId row[4]=LStat row[5]=MarkId row[6]=MD5 + * row[3]=JobId row[4]=LStat row[5]=DeltaSeq row[6]=MD5 */ static int accurate_list_handler(void *ctx, int num_fields, char **row) { diff --git a/bacula/src/dird/ua_tree.c b/bacula/src/dird/ua_tree.c index bba9112667..71117a94ef 100644 --- a/bacula/src/dird/ua_tree.c +++ b/bacula/src/dird/ua_tree.c @@ -181,7 +181,7 @@ bool user_select_files_from_tree(TREE_CTX *tree) * * See uar_sel_files in sql_cmds.c for query that calls us. * row[0]=Path, row[1]=Filename, row[2]=FileIndex - * row[3]=JobId row[4]=LStat row[5]=MarkId + * row[3]=JobId row[4]=LStat row[5]=DeltaSeq */ int insert_tree_handler(void *ctx, int num_fields, char **row) { -- 2.39.5