svn commit: samba r19685 - in branches/SAMBA_3_0/source/tdb: common include tools

vlendec at samba.org vlendec at samba.org
Mon Nov 13 09:34:55 GMT 2006


Author: vlendec
Date: 2006-11-13 09:34:55 +0000 (Mon, 13 Nov 2006)
New Revision: 19685

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=19685

Log:
Two changes inspired by problems with huge tdbs. tdbtool's list command now
prints the hash on every record for easier awk'ing, and tdbbackup allows a
different hash chain length on the backed up tdb.

Jeremy, G?\195?\188nther, this might be interesting for you huge domains. Not only
locking.tdb, also the winbind ones might grow huge.

In the installation I fixed with this winbind spent a huge amount of CPU
spinning through a degenerated winbindd_idmap.tdb with entries for more than
15.000 users. With a default number of hash chains of 131 on that tdb you can
imagine that the lists get large.

Not merging to 4, I don't get tdbbackup to compile there right now.

What about changing the global default hash chain number to be dramatically
larger? Disk is cheap these days.

Volker

Modified:
   branches/SAMBA_3_0/source/tdb/common/dump.c
   branches/SAMBA_3_0/source/tdb/common/tdbback.c
   branches/SAMBA_3_0/source/tdb/include/tdbback.h
   branches/SAMBA_3_0/source/tdb/tools/tdbbackup.c


Changeset:
Modified: branches/SAMBA_3_0/source/tdb/common/dump.c
===================================================================
--- branches/SAMBA_3_0/source/tdb/common/dump.c	2006-11-13 09:18:36 UTC (rev 19684)
+++ branches/SAMBA_3_0/source/tdb/common/dump.c	2006-11-13 09:34:55 UTC (rev 19685)
@@ -28,7 +28,8 @@
 
 #include "tdb_private.h"
 
-static tdb_off_t tdb_dump_record(struct tdb_context *tdb, tdb_off_t offset)
+static tdb_off_t tdb_dump_record(struct tdb_context *tdb, int hash,
+				 tdb_off_t offset)
 {
 	struct list_struct rec;
 	tdb_off_t tailer_ofs, tailer;
@@ -39,8 +40,10 @@
 		return 0;
 	}
 
-	printf(" rec: offset=0x%08x next=0x%08x rec_len=%d key_len=%d data_len=%d full_hash=0x%x magic=0x%x\n",
-	       offset, rec.next, rec.rec_len, rec.key_len, rec.data_len, rec.full_hash, rec.magic);
+	printf(" rec: hash=%d, offset=0x%08x next=0x%08x rec_len=%d "
+	       "key_len=%d data_len=%d full_hash=0x%x magic=0x%x\n",
+	       hash, offset, rec.next, rec.rec_len, rec.key_len, rec.data_len,
+	       rec.full_hash, rec.magic);
 
 	tailer_ofs = offset + sizeof(rec) + rec.rec_len - sizeof(tdb_off_t);
 
@@ -72,7 +75,7 @@
 		printf("hash=%d\n", i);
 
 	while (rec_ptr) {
-		rec_ptr = tdb_dump_record(tdb, rec_ptr);
+		rec_ptr = tdb_dump_record(tdb, i, rec_ptr);
 	}
 
 	return tdb_unlock(tdb, i, F_WRLCK);

Modified: branches/SAMBA_3_0/source/tdb/common/tdbback.c
===================================================================
--- branches/SAMBA_3_0/source/tdb/common/tdbback.c	2006-11-13 09:18:36 UTC (rev 19684)
+++ branches/SAMBA_3_0/source/tdb/common/tdbback.c	2006-11-13 09:34:55 UTC (rev 19685)
@@ -95,7 +95,7 @@
   only doing the backup if its OK
   this function is also used for restore
 */
-int backup_tdb(const char *old_name, const char *new_name)
+int backup_tdb(const char *old_name, const char *new_name, int hash_size)
 {
 	TDB_CONTEXT *tdb;
 	TDB_CONTEXT *tdb_new;
@@ -122,7 +122,8 @@
 
 	/* create the new tdb */
 	unlink(tmp_name);
-	tdb_new = tdb_open(tmp_name, tdb_hash_size(tdb),
+	tdb_new = tdb_open(tmp_name,
+			   hash_size ? hash_size : tdb_hash_size(tdb),
 			   TDB_DEFAULT, O_RDWR|O_CREAT|O_EXCL, 
 			   st.st_mode & 0777);
 	if (!tdb_new) {
@@ -217,7 +218,7 @@
 	/* count is < 0 means an error */
 	if (count < 0) {
 		printf("restoring %s\n", fname);
-		return backup_tdb(bak_name, fname);
+		return backup_tdb(bak_name, fname, 0);
 	}
 
 	printf("%s : %d records\n", fname, count);

Modified: branches/SAMBA_3_0/source/tdb/include/tdbback.h
===================================================================
--- branches/SAMBA_3_0/source/tdb/include/tdbback.h	2006-11-13 09:18:36 UTC (rev 19684)
+++ branches/SAMBA_3_0/source/tdb/include/tdbback.h	2006-11-13 09:34:55 UTC (rev 19685)
@@ -19,5 +19,5 @@
 */
 
 char *add_suffix(const char *name, const char *suffix);
-int backup_tdb(const char *old_name, const char *new_name);
+int backup_tdb(const char *old_name, const char *new_name, int hash_size);
 int verify_tdb(const char *fname, const char *bak_name);

Modified: branches/SAMBA_3_0/source/tdb/tools/tdbbackup.c
===================================================================
--- branches/SAMBA_3_0/source/tdb/tools/tdbbackup.c	2006-11-13 09:18:36 UTC (rev 19684)
+++ branches/SAMBA_3_0/source/tdb/tools/tdbbackup.c	2006-11-13 09:34:55 UTC (rev 19685)
@@ -93,6 +93,7 @@
 	printf("   -h            this help message\n");
 	printf("   -s suffix     set the backup suffix\n");
 	printf("   -v            verify mode (restore if corrupt)\n");
+	printf("   -n hashsize   set the new hash size for the backup\n");
 }
 		
 
@@ -102,9 +103,10 @@
 	int ret = 0;
 	int c;
 	int verify = 0;
+	int hashsize = 0;
 	const char *suffix = ".bak";
 
-	while ((c = getopt(argc, argv, "vhs:")) != -1) {
+	while ((c = getopt(argc, argv, "vhs:n:")) != -1) {
 		switch (c) {
 		case 'h':
 			usage();
@@ -115,6 +117,9 @@
 		case 's':
 			suffix = optarg;
 			break;
+		case 'n':
+			hashsize = atoi(optarg);
+			break;
 		}
 	}
 
@@ -138,7 +143,7 @@
 			}
 		} else {
 			if (file_newer(fname, bak_name) &&
-			    backup_tdb(fname, bak_name) != 0) {
+			    backup_tdb(fname, bak_name, hashsize) != 0) {
 				ret = 1;
 			}
 		}



More information about the samba-cvs mailing list