dbwrap_ctdb: factor out a db_ctdb_try_parse_local_record() function
authorRalph Boehme <slow@samba.org>
Thu, 23 Feb 2017 17:28:32 +0000 (18:28 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 18 Apr 2017 20:54:16 +0000 (22:54 +0200)
Pair-programmed-with: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Ralph Boehme <slow@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/dbwrap/dbwrap_ctdb.c

index 88db20401fe7722a22f5dfc8478d572601d995c2..e0223eeaf4e6e2e9610c55e4d1ee9f16ed6fdf3c 100644 (file)
@@ -1254,22 +1254,11 @@ static void db_ctdb_parse_record_parser_nonpersistent(
        }
 }
 
-static NTSTATUS db_ctdb_parse_record(struct db_context *db, TDB_DATA key,
-                                    void (*parser)(TDB_DATA key,
-                                                   TDB_DATA data,
-                                                   void *private_data),
-                                    void *private_data)
+static NTSTATUS db_ctdb_try_parse_local_record(struct db_ctdb_ctx *ctx,
+                                              TDB_DATA key,
+                                              struct db_ctdb_parse_record_state *state)
 {
-       struct db_ctdb_ctx *ctx = talloc_get_type_abort(
-               db->private_data, struct db_ctdb_ctx);
-       struct db_ctdb_parse_record_state state;
        NTSTATUS status;
-       int ret;
-
-       state.parser = parser;
-       state.private_data = private_data;
-       state.my_vnn = ctdbd_vnn(ctx->conn);
-       state.empty_record = false;
 
        if (ctx->transaction != NULL) {
                struct db_ctdb_transaction_handle *h = ctx->transaction;
@@ -1280,28 +1269,28 @@ static NTSTATUS db_ctdb_parse_record(struct db_context *db, TDB_DATA key,
                 */
 
                found = parse_newest_in_marshall_buffer(
-                       h->m_write, key, db_ctdb_parse_record_parser, &state);
+                       h->m_write, key, db_ctdb_parse_record_parser, state);
 
                if (found) {
                        return NT_STATUS_OK;
                }
        }
 
-       if (db->persistent) {
+       if (ctx->db->persistent) {
                /*
                 * Persistent db, but not found in the transaction buffer
                 */
                return db_ctdb_ltdb_parse(
-                       ctx, key, db_ctdb_parse_record_parser, &state);
+                       ctx, key, db_ctdb_parse_record_parser, state);
        }
 
-       state.done = false;
-       state.ask_for_readonly_copy = false;
+       state->done = false;
+       state->ask_for_readonly_copy = false;
 
        status = db_ctdb_ltdb_parse(
-               ctx, key, db_ctdb_parse_record_parser_nonpersistent, &state);
-       if (NT_STATUS_IS_OK(status) && state.done) {
-               if (state.empty_record) {
+               ctx, key, db_ctdb_parse_record_parser_nonpersistent, state);
+       if (NT_STATUS_IS_OK(status) && state->done) {
+               if (state->empty_record) {
                        /*
                         * We know authoritatively, that this is an empty
                         * record. Since ctdb does not distinguish between empty
@@ -1318,6 +1307,31 @@ static NTSTATUS db_ctdb_parse_record(struct db_context *db, TDB_DATA key,
                return NT_STATUS_OK;
        }
 
+       return NT_STATUS_MORE_PROCESSING_REQUIRED;
+}
+
+static NTSTATUS db_ctdb_parse_record(struct db_context *db, TDB_DATA key,
+                                    void (*parser)(TDB_DATA key,
+                                                   TDB_DATA data,
+                                                   void *private_data),
+                                    void *private_data)
+{
+       struct db_ctdb_ctx *ctx = talloc_get_type_abort(
+               db->private_data, struct db_ctdb_ctx);
+       struct db_ctdb_parse_record_state state;
+       NTSTATUS status;
+       int ret;
+
+       state.parser = parser;
+       state.private_data = private_data;
+       state.my_vnn = ctdbd_vnn(ctx->conn);
+       state.empty_record = false;
+
+       status = db_ctdb_try_parse_local_record(ctx, key, &state);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
+               return status;
+       }
+
        ret = ctdbd_parse(ctx->conn, ctx->db_id, key,
                          state.ask_for_readonly_copy, parser, private_data);
        if (ret != 0) {