smbd/locking: make use of the same tdb hash_size and flags for all SMB related tdb's
authorStefan Metzmacher <metze@samba.org>
Mon, 17 Jun 2019 14:36:01 +0000 (07:36 -0700)
committerStefan Metzmacher <metze@samba.org>
Mon, 19 Dec 2022 16:40:15 +0000 (16:40 +0000)
It's good to have a consistent set of hash_size/flags for all aspects of
an open file handle. Currently we're using 4 databases:
smbXsrv_open_global.tdb, leases.tdb, locking.tdb and brlock.tdb.

While at it also crank up the hashsize if the smbXsrv_tcon and smbXsrv_session
TDBs. The default TDB hash size is insanely small and disk space is cheap these
days, by going with the much larger hash size we get O(1) lookup instead of O(n)
for moderate to large loads with a few thousand objects.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Mon Dec 19 16:40:15 UTC 2022 on sn-devel-184

source3/include/local.h
source3/locking/brlock.c
source3/locking/leases_db.c
source3/locking/share_mode_lock.c
source3/smbd/smbXsrv_open.c
source3/smbd/smbXsrv_session.c
source3/smbd/smbXsrv_tcon.c

index 297e5572fdb366634546d7c33067253f16966009..db53698ec4415558bae09b8b4450a00ecdf36069 100644 (file)
 
 #define MAX_LDAP_REPLICATION_SLEEP_TIME 5000 /* In milliseconds. */
 
-/* tdb hash size for the open database. */
-#define SMB_OPEN_DATABASE_TDB_HASH_SIZE 10007
+/* tdb hash size for the databases having one entry per open file. */
+#define SMBD_VOLATILE_TDB_HASH_SIZE 10007
+
+/* tdb flags for the databases having one entry per open file. */
+#define SMBD_VOLATILE_TDB_FLAGS \
+       (TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH)
 
 /* Characters we disallow in sharenames. */
 #define INVALID_SHARENAME_CHARS "%<>*?|/\\+=;:\","
index d2e4abf48d73e8612a703a3a801eaa233d133865..d065c7fe03e85222c2b8e0fe7e681a311beb544f 100644 (file)
@@ -369,12 +369,7 @@ void brl_init(bool read_only)
                return;
        }
 
-       tdb_flags =
-               TDB_DEFAULT|
-               TDB_VOLATILE|
-               TDB_CLEAR_IF_FIRST|
-               TDB_INCOMPATIBLE_HASH|
-               TDB_SEQNUM;
+       tdb_flags = SMBD_VOLATILE_TDB_FLAGS | TDB_SEQNUM;
 
        db_path = lock_path(talloc_tos(), "brlock.tdb");
        if (db_path == NULL) {
@@ -383,7 +378,7 @@ void brl_init(bool read_only)
        }
 
        brlock_db = db_open(NULL, db_path,
-                           SMB_OPEN_DATABASE_TDB_HASH_SIZE, tdb_flags,
+                           SMBD_VOLATILE_TDB_HASH_SIZE, tdb_flags,
                            read_only?O_RDONLY:(O_RDWR|O_CREAT), 0644,
                            DBWRAP_LOCK_ORDER_2, DBWRAP_FLAG_NONE);
        if (!brlock_db) {
index 855d6143ad71ef9f1e52ba68a170ef3a84b9a112..eae58f5fc824df579c23091ce65afc06636779ce 100644 (file)
@@ -46,12 +46,10 @@ bool leases_db_init(bool read_only)
                return false;
        }
 
-       leases_db = db_open(NULL, db_path, 0,
-                           TDB_DEFAULT|
-                           TDB_VOLATILE|
-                           TDB_CLEAR_IF_FIRST|
-                           TDB_SEQNUM|
-                           TDB_INCOMPATIBLE_HASH,
+       leases_db = db_open(NULL, db_path,
+                           SMBD_VOLATILE_TDB_HASH_SIZE,
+                           SMBD_VOLATILE_TDB_FLAGS |
+                           TDB_SEQNUM,
                            read_only ? O_RDONLY : O_RDWR|O_CREAT, 0644,
                            DBWRAP_LOCK_ORDER_4, DBWRAP_FLAG_NONE);
        TALLOC_FREE(db_path);
index 909bfdfbccecbb88a54a5dfb052f7d596767d369..e123084677dff9fbbc533e303eb73033ce7ba9b0 100644 (file)
@@ -125,11 +125,8 @@ static bool locking_init_internal(bool read_only)
        }
 
        backend = db_open(NULL, db_path,
-                         SMB_OPEN_DATABASE_TDB_HASH_SIZE,
-                         TDB_DEFAULT|
-                         TDB_VOLATILE|
-                         TDB_CLEAR_IF_FIRST|
-                         TDB_INCOMPATIBLE_HASH|
+                         SMBD_VOLATILE_TDB_HASH_SIZE,
+                         SMBD_VOLATILE_TDB_FLAGS |
                          TDB_SEQNUM,
                          read_only?O_RDONLY:O_RDWR|O_CREAT, 0644,
                          DBWRAP_LOCK_ORDER_NONE,
index 91f2f8a83cd06145ea45b3440789a0815cf127f4..366a35b1e2ff5413cb0a61a848fabadb013d0637 100644 (file)
@@ -64,11 +64,8 @@ NTSTATUS smbXsrv_open_global_init(void)
        }
 
        db_ctx = db_open(NULL, global_path,
-                        0, /* hash_size */
-                        TDB_DEFAULT |
-                        TDB_CLEAR_IF_FIRST |
-                        TDB_VOLATILE |
-                        TDB_INCOMPATIBLE_HASH,
+                        SMBD_VOLATILE_TDB_HASH_SIZE,
+                        SMBD_VOLATILE_TDB_FLAGS,
                         O_RDWR | O_CREAT, 0600,
                         DBWRAP_LOCK_ORDER_1,
                         DBWRAP_FLAG_NONE);
index cf09b56803a11abd2fb10c6d6f2e01748fa35379..57ec395186cb0cf7a1b83ea58cafe2910ad47515 100644 (file)
@@ -74,11 +74,8 @@ NTSTATUS smbXsrv_session_global_init(struct messaging_context *msg_ctx)
        }
 
        backend = db_open(NULL, global_path,
-                         0, /* hash_size */
-                         TDB_DEFAULT |
-                         TDB_CLEAR_IF_FIRST |
-                         TDB_VOLATILE |
-                         TDB_INCOMPATIBLE_HASH,
+                         SMBD_VOLATILE_TDB_HASH_SIZE,
+                         SMBD_VOLATILE_TDB_FLAGS,
                          O_RDWR | O_CREAT, 0600,
                          DBWRAP_LOCK_ORDER_1,
                          DBWRAP_FLAG_NONE);
index 0aa35602b6c5224b78d9a9186293f3c631687703..1ee1bbba4f39594ff16abf84d8c9c4bcfa7b7987 100644 (file)
@@ -61,11 +61,8 @@ NTSTATUS smbXsrv_tcon_global_init(void)
        }
 
        db_ctx = db_open(NULL, global_path,
-                        0, /* hash_size */
-                        TDB_DEFAULT |
-                        TDB_CLEAR_IF_FIRST |
-                        TDB_VOLATILE |
-                        TDB_INCOMPATIBLE_HASH,
+                        SMBD_VOLATILE_TDB_HASH_SIZE,
+                        SMBD_VOLATILE_TDB_FLAGS,
                         O_RDWR | O_CREAT, 0600,
                         DBWRAP_LOCK_ORDER_1,
                         DBWRAP_FLAG_NONE);