]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#10275 mdb_load: add -Q option to use NOSYNC for faster loading
authorGary Wicker <gkwicker@amazon.com>
Fri, 25 Oct 2024 01:05:00 +0000 (01:05 +0000)
committerHoward Chu <hyc@openldap.org>
Sat, 26 Oct 2024 20:26:17 +0000 (21:26 +0100)
libraries/liblmdb/mdb_load.1
libraries/liblmdb/mdb_load.c

index 6f1c8a71967deb4a4de6eb8be1c701d97b11a3de..741555f87c7140d00dce24891f762a7dd1f71142 100644 (file)
@@ -18,6 +18,8 @@ mdb_load \- LMDB environment import tool
 [\c
 .BR \-N ]
 [\c
+.BR \-Q ]
+[\c
 .BR \-T ]
 .BR \ envpath
 .SH DESCRIPTION
@@ -58,6 +60,9 @@ Load a specific subdatabase. If no database is specified, data is loaded into th
 .BR \-N
 Don't overwrite existing records when loading into an already existing database; just skip them.
 .TP
+.BR \-Q
+Quick mode, uses MDB_NOSYNC for faster loading.  Forces sync with mdb_env_sync() before exiting.
+.TP
 .BR \-T
 Load data from simple text files. The input must be paired lines of text, where the first
 line of the pair is the key item, and the second line of the pair is its corresponding
index cba6c06003fa5ef29be1d0d221ee8c61b5f01228..d266b4f6e198d078854733a5a9ab1937a122ee70 100644 (file)
@@ -311,10 +311,11 @@ int main(int argc, char *argv[])
         * -n: use NOSUBDIR flag on env_open
         * -s: load into named subDB
         * -N: use NOOVERWRITE on puts
+        * -Q: quick mode using NOSYNC
         * -T: read plaintext
         * -V: print version and exit
         */
-       while ((i = getopt(argc, argv, "af:ns:NTV")) != EOF) {
+       while ((i = getopt(argc, argv, "af:ns:NQTV")) != EOF) {
                switch(i) {
                case 'V':
                        printf("%s\n", MDB_VERSION_STRING);
@@ -339,6 +340,9 @@ int main(int argc, char *argv[])
                case 'N':
                        putflags = MDB_NOOVERWRITE|MDB_NODUPDATA;
                        break;
+               case 'Q':
+                       envflags |= MDB_NOSYNC;
+                       break;
                case 'T':
                        mode |= NOHDR | PRINT;
                        break;
@@ -403,9 +407,9 @@ int main(int argc, char *argv[])
                        goto env_close;
                }
 
-               rc = mdb_open(txn, subname, flags|MDB_CREATE, &dbi);
+               rc = mdb_dbi_open(txn, subname, flags|MDB_CREATE, &dbi);
                if (rc) {
-                       fprintf(stderr, "mdb_open failed, error %d %s\n", rc, mdb_strerror(rc));
+                       fprintf(stderr, "mdb_dbi_open failed, error %d %s\n", rc, mdb_strerror(rc));
                        goto txn_abort;
                }
                prevk.mv_size = 0;
@@ -486,6 +490,13 @@ int main(int argc, char *argv[])
                                prog, lineno, mdb_strerror(rc));
                        goto env_close;
                }
+               if (envflags & MDB_NOSYNC) {
+                       rc = mdb_env_sync(env, 1);
+                       if (rc) {
+                               fprintf(stderr, "mdb_env_sync failed, error %d %s\n", rc, mdb_strerror(rc));
+                               goto env_close;
+                       }
+               }
                mdb_dbi_close(env, dbi);
        }