Browse Source

tdb2: unify tdb1_append into tdb_append

Switch on the TDB_VERSION1 flag.
Rusty Russell 14 years ago
parent
commit
8bc38cb177
5 changed files with 11 additions and 4 deletions
  1. 1 0
      ccan/tdb2/private.h
  2. 6 0
      ccan/tdb2/tdb.c
  3. 0 2
      ccan/tdb2/tdb1.h
  4. 2 0
      ccan/tdb2/tdb1_tdb.c
  5. 2 2
      ccan/tdb2/test/run-tdb1-zero-append.c

+ 1 - 0
ccan/tdb2/private.h

@@ -650,6 +650,7 @@ int tdb1_transaction_cancel(struct tdb_context *tdb);
 int tdb1_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
 int tdb1_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
 enum TDB_ERROR tdb1_fetch(struct tdb_context *tdb, TDB_DATA key,
 enum TDB_ERROR tdb1_fetch(struct tdb_context *tdb, TDB_DATA key,
 			  TDB_DATA *data);
 			  TDB_DATA *data);
+int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
 
 
 /* tdb.c: */
 /* tdb.c: */
 enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
 enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,

+ 6 - 0
ccan/tdb2/tdb.c

@@ -183,6 +183,12 @@ enum TDB_ERROR tdb_append(struct tdb_context *tdb,
 	struct tdb_data new_dbuf;
 	struct tdb_data new_dbuf;
 	enum TDB_ERROR ecode;
 	enum TDB_ERROR ecode;
 
 
+	if (tdb->flags & TDB_VERSION1) {
+		if (tdb1_append(tdb, key, dbuf) == -1)
+			return tdb->last_error;
+		return TDB_SUCCESS;
+	}
+
 	off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL);
 	off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL);
 	if (TDB_OFF_IS_ERR(off)) {
 	if (TDB_OFF_IS_ERR(off)) {
 		return tdb->last_error = off;
 		return tdb->last_error = off;

+ 0 - 2
ccan/tdb2/tdb1.h

@@ -47,8 +47,6 @@ int tdb1_parse_record(struct tdb_context *tdb, TDB_DATA key,
 
 
 int tdb1_delete(struct tdb_context *tdb, TDB_DATA key);
 int tdb1_delete(struct tdb_context *tdb, TDB_DATA key);
 
 
-int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
-
 TDB_DATA tdb1_firstkey(struct tdb_context *tdb);
 TDB_DATA tdb1_firstkey(struct tdb_context *tdb);
 
 
 TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key);
 TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key);

+ 2 - 0
ccan/tdb2/tdb1_tdb.c

@@ -627,6 +627,8 @@ int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf)
 	TDB_DATA dbuf;
 	TDB_DATA dbuf;
 	int ret = -1;
 	int ret = -1;
 
 
+	assert(tdb->flags & TDB_VERSION1);
+
 	/* find which hash bucket it is in */
 	/* find which hash bucket it is in */
 	hash = tdb_hash(tdb, key.dptr, key.dsize);
 	hash = tdb_hash(tdb, key.dptr, key.dsize);
 	if (tdb1_lock(tdb, TDB1_BUCKET(hash), F_WRLCK) == -1)
 	if (tdb1_lock(tdb, TDB1_BUCKET(hash), F_WRLCK) == -1)

+ 2 - 2
ccan/tdb2/test/run-tdb1-zero-append.c

@@ -25,8 +25,8 @@ int main(int argc, char *argv[])
 	data.dptr = (void *)"world";
 	data.dptr = (void *)"world";
 	data.dsize = 0;
 	data.dsize = 0;
 
 
-	ok1(tdb1_append(tdb, key, data) == 0);
-	ok1(tdb1_append(tdb, key, data) == 0);
+	ok1(tdb_append(tdb, key, data) == TDB_SUCCESS);
+	ok1(tdb_append(tdb, key, data) == TDB_SUCCESS);
 	ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
 	ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
 	ok1(data.dsize == 0);
 	ok1(data.dsize == 0);
 	free(data.dptr);
 	free(data.dptr);