Commit b44978e1 authored by Rusty Russell's avatar Rusty Russell

tdb2: use direct access for tdb_read_off/tdb_write_off

This is one case where getting rid of tdb_get() cost us.  Also, we
add more read-only checks.

Before we removed tdb_get:
Adding 1000000 records:  6480 ns (59900296 bytes)
Finding 1000000 records:  2839 ns (59900296 bytes)
Missing 1000000 records:  2485 ns (59900296 bytes)
Traversing 1000000 records:  2598 ns (59900296 bytes)
Deleting 1000000 records:  5342 ns (59900296 bytes)
Re-adding 1000000 records:  5613 ns (59900296 bytes)
Appending 1000000 records:  12194 ns (93594224 bytes)
Churning 1000000 records:  14549 ns (93594224 bytes)

Now:
Adding 1000000 records:  6307 ns (59900296 bytes)
Finding 1000000 records:  2801 ns (59900296 bytes)
Missing 1000000 records:  2515 ns (59900296 bytes)
Traversing 1000000 records:  2579 ns (59900296 bytes)
Deleting 1000000 records:  5225 ns (59900296 bytes)
Re-adding 1000000 records:  5878 ns (59900296 bytes)
Appending 1000000 records:  12665 ns (93594224 bytes)
Churning 1000000 records:  16090 ns (93594224 bytes)
parent 96b169e9
...@@ -179,6 +179,12 @@ int zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len) ...@@ -179,6 +179,12 @@ int zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len)
{ {
char buf[8192] = { 0 }; char buf[8192] = { 0 };
void *p = tdb->methods->direct(tdb, off, len); void *p = tdb->methods->direct(tdb, off, len);
if (tdb->read_only) {
tdb->ecode = TDB_ERR_RDONLY;
return -1;
}
if (p) { if (p) {
memset(p, 0, len); memset(p, 0, len);
return 0; return 0;
...@@ -197,6 +203,12 @@ tdb_off_t tdb_read_off(struct tdb_context *tdb, tdb_off_t off) ...@@ -197,6 +203,12 @@ tdb_off_t tdb_read_off(struct tdb_context *tdb, tdb_off_t off)
{ {
tdb_off_t ret; tdb_off_t ret;
if (likely(!(tdb->flags & TDB_CONVERT))) {
tdb_off_t *p = tdb->methods->direct(tdb, off, sizeof(*p));
if (p)
return *p;
}
if (tdb_read_convert(tdb, off, &ret, sizeof(ret)) == -1) if (tdb_read_convert(tdb, off, &ret, sizeof(ret)) == -1)
return TDB_OFF_ERR; return TDB_OFF_ERR;
return ret; return ret;
...@@ -349,6 +361,18 @@ int tdb_read_convert(struct tdb_context *tdb, tdb_off_t off, ...@@ -349,6 +361,18 @@ int tdb_read_convert(struct tdb_context *tdb, tdb_off_t off,
int tdb_write_off(struct tdb_context *tdb, tdb_off_t off, tdb_off_t val) int tdb_write_off(struct tdb_context *tdb, tdb_off_t off, tdb_off_t val)
{ {
if (tdb->read_only) {
tdb->ecode = TDB_ERR_RDONLY;
return -1;
}
if (likely(!(tdb->flags & TDB_CONVERT))) {
tdb_off_t *p = tdb->methods->direct(tdb, off, sizeof(*p));
if (p) {
*p = val;
return 0;
}
}
return tdb_write_convert(tdb, off, &val, sizeof(val)); return tdb_write_convert(tdb, off, &val, sizeof(val));
} }
...@@ -470,6 +494,11 @@ void *tdb_access_write(struct tdb_context *tdb, ...@@ -470,6 +494,11 @@ void *tdb_access_write(struct tdb_context *tdb,
{ {
void *ret = NULL; void *ret = NULL;
if (tdb->read_only) {
tdb->ecode = TDB_ERR_RDONLY;
return NULL;
}
if (likely(!(tdb->flags & TDB_CONVERT))) if (likely(!(tdb->flags & TDB_CONVERT)))
ret = tdb->methods->direct(tdb, off, len); ret = tdb->methods->direct(tdb, off, len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment