/* * row_remove -- * Remove an row from a row-store file. */ static void row_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp) { WT_SESSION *session; int notfound, ret; session = cursor->session; key_gen((uint8_t *)key->data, &key->size, keyno, 0); /* Log the operation */ if (g.logging == LOG_OPS) (void)session->msg_printf( session, "%-10s%" PRIu64, "remove", keyno); cursor->set_key(cursor, key); ret = cursor->remove(cursor); if (ret != 0 && ret != WT_NOTFOUND) die(ret, "row_remove: remove %" PRIu64 " by key", keyno); *notfoundp = ret == WT_NOTFOUND; if (!SINGLETHREADED) return; bdb_remove(keyno, ¬found); (void)notfound_chk("row_remove", ret, notfound, keyno); }
/* * col_remove -- * Remove a row from a column-store file. */ static void col_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp) { WT_SESSION *session; int notfound, ret; session = cursor->session; /* Log the operation */ if (g.logging == LOG_OPS) (void)session->msg_printf( session, "%-10s%" PRIu64, "remove", keyno); cursor->set_key(cursor, keyno); ret = cursor->remove(cursor); if (ret != 0 && ret != WT_NOTFOUND) die(ret, "col_remove: remove %" PRIu64 " by key", keyno); *notfoundp = ret == WT_NOTFOUND; if (!SINGLETHREADED) return; /* * Deleting a fixed-length item is the same as setting the bits to 0; * do the same thing for the BDB store. */ if (g.c_file_type == FIX) { key_gen((uint8_t *)key->data, &key->size, keyno, 0); bdb_update(key->data, key->size, "\0", 1, ¬found); } else bdb_remove(keyno, ¬found); (void)notfound_chk("col_remove", ret, notfound, keyno); }
/* * row_remove -- * Remove an row from a row-store file. */ static int row_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp) { WT_SESSION *session; int notfound, ret; session = cursor->session; key_gen((uint8_t *)key->data, &key->size, keyno, 0); /* Log the operation */ if (g.logging == LOG_OPS) (void)g.wt_api->msg_printf( g.wt_api, session, "%-10s%" PRIu64, "remove", keyno); cursor->set_key(cursor, key); /* We use the cursor in overwrite mode, check for existence. */ if ((ret = cursor->search(cursor)) == 0) ret = cursor->remove(cursor); if (ret == WT_DEADLOCK) return (WT_DEADLOCK); if (ret != 0 && ret != WT_NOTFOUND) die(ret, "row_remove: remove %" PRIu64 " by key", keyno); *notfoundp = (ret == WT_NOTFOUND); if (!SINGLETHREADED) return (0); bdb_remove(keyno, ¬found); (void)notfound_chk("row_remove", ret, notfound, keyno); return (0); }
/* * row_update -- * Update a row in a row-store file. */ static void row_update( WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno, int insert) { WT_SESSION *session; int notfound, ret; session = cursor->session; key_gen((uint8_t *)key->data, &key->size, keyno, insert); value_gen((uint8_t *)value->data, &value->size, keyno); /* Log the operation */ if (g.logging == LOG_OPS) (void)session->msg_printf(session, "%-10s{%.*s}\n%-10s{%.*s}", insert ? "insertK" : "putK", (int)key->size, (char *)key->data, insert ? "insertV" : "putV", (int)value->size, (char *)value->data); cursor->set_key(cursor, key); cursor->set_value(cursor, value); ret = cursor->insert(cursor); if (ret != 0 && ret != WT_NOTFOUND) die(ret, "row_update: %s row %" PRIu64 " by key", insert ? "insert" : "update", keyno); if (!SINGLETHREADED) return; bdb_update(key->data, key->size, value->data, value->size, ¬found); (void)notfound_chk("row_update", ret, notfound, keyno); }
/* * row_insert -- * Insert a row in a row-store file. */ static int row_insert( WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno) { WT_SESSION *session; int notfound, ret; session = cursor->session; key_gen((uint8_t *)key->data, &key->size, keyno, 1); value_gen((uint8_t *)value->data, &value->size, keyno); /* Log the operation */ if (g.logging == LOG_OPS) (void)g.wt_api->msg_printf(g.wt_api, session, "%-10s{%.*s}\n%-10s{%.*s}", "insertK", (int)key->size, (char *)key->data, "insertV", (int)value->size, (char *)value->data); cursor->set_key(cursor, key); cursor->set_value(cursor, value); ret = cursor->insert(cursor); if (ret == WT_DEADLOCK) return (WT_DEADLOCK); if (ret != 0 && ret != WT_NOTFOUND) die(ret, "row_insert: insert row %" PRIu64 " by key", keyno); if (!SINGLETHREADED) return (0); bdb_update(key->data, key->size, value->data, value->size, ¬found); (void)notfound_chk("row_insert", ret, notfound, keyno); return (0); }
/* * col_update -- * Update a row in a column-store file. */ static int col_update(TINFO *tinfo, WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno) { WT_SESSION *session; int ret; session = cursor->session; val_gen(&tinfo->rnd, (uint8_t *)value->data, &value->size, keyno); /* Log the operation */ if (g.logging == LOG_OPS) { if (g.type == FIX) (void)g.wt_api->msg_printf(g.wt_api, session, "%-10s%" PRIu64 " {0x%02" PRIx8 "}", "update", keyno, ((uint8_t *)value->data)[0]); else (void)g.wt_api->msg_printf(g.wt_api, session, "%-10s%" PRIu64 " {%.*s}", "update", keyno, (int)value->size, (char *)value->data); } cursor->set_key(cursor, keyno); if (g.type == FIX) cursor->set_value(cursor, *(uint8_t *)value->data); else cursor->set_value(cursor, value); ret = cursor->update(cursor); if (ret == WT_ROLLBACK) return (WT_ROLLBACK); if (ret != 0 && ret != WT_NOTFOUND) die(ret, "col_update: %" PRIu64, keyno); #ifdef HAVE_BERKELEY_DB if (!SINGLETHREADED) return (0); { int notfound; key_gen((uint8_t *)key->data, &key->size, keyno); bdb_update(key->data, key->size, value->data, value->size, ¬found); (void)notfound_chk("col_update", ret, notfound, keyno); } #else (void)key; /* [-Wunused-variable] */ #endif return (0); }
/* * col_remove -- * Remove a row from a column-store file. */ static int col_remove(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int *notfoundp) { WT_SESSION *session; int ret; session = cursor->session; /* Log the operation */ if (g.logging == LOG_OPS) (void)g.wt_api->msg_printf( g.wt_api, session, "%-10s%" PRIu64, "remove", keyno); cursor->set_key(cursor, keyno); /* We use the cursor in overwrite mode, check for existence. */ if ((ret = cursor->search(cursor)) == 0) ret = cursor->remove(cursor); if (ret == WT_ROLLBACK) return (WT_ROLLBACK); if (ret != 0 && ret != WT_NOTFOUND) testutil_die(ret, "col_remove: remove %" PRIu64 " by key", keyno); *notfoundp = (ret == WT_NOTFOUND); #ifdef HAVE_BERKELEY_DB if (!SINGLETHREADED) return (0); { int notfound; /* * Deleting a fixed-length item is the same as setting the bits to 0; * do the same thing for the BDB store. */ if (g.type == FIX) { key_gen((uint8_t *)key->data, &key->size, keyno); bdb_update(key->data, key->size, "\0", 1, ¬found); } else bdb_remove(keyno, ¬found); (void)notfound_chk("col_remove", ret, notfound, keyno); } #else (void)key; /* [-Wunused-variable] */ #endif return (0); }
/* * col_update -- * Update a row in a column-store file. */ static int col_update(WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno) { WT_SESSION *session; int notfound, ret; session = cursor->session; value_gen((uint8_t *)value->data, &value->size, keyno); /* Log the operation */ if (g.logging == LOG_OPS) { if (g.type == FIX) (void)g.wt_api->msg_printf(g.wt_api, session, "%-10s%" PRIu64 " {0x%02" PRIx8 "}", "update", keyno, ((uint8_t *)value->data)[0]); else (void)g.wt_api->msg_printf(g.wt_api, session, "%-10s%" PRIu64 " {%.*s}", "update", keyno, (int)value->size, (char *)value->data); } cursor->set_key(cursor, keyno); if (g.type == FIX) cursor->set_value(cursor, *(uint8_t *)value->data); else cursor->set_value(cursor, value); ret = cursor->update(cursor); if (ret == WT_DEADLOCK) return (WT_DEADLOCK); if (ret != 0 && ret != WT_NOTFOUND) die(ret, "col_update: %" PRIu64, keyno); if (!SINGLETHREADED) return (0); key_gen((uint8_t *)key->data, &key->size, keyno, 0); bdb_update(key->data, key->size, value->data, value->size, ¬found); (void)notfound_chk("col_update", ret, notfound, keyno); return (0); }
/* * row_update -- * Update a row in a row-store file. */ static int row_update(TINFO *tinfo, WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno) { WT_SESSION *session; int ret; session = cursor->session; key_gen((uint8_t *)key->data, &key->size, keyno); val_gen(&tinfo->rnd, (uint8_t *)value->data, &value->size, keyno); /* Log the operation */ if (g.logging == LOG_OPS) (void)g.wt_api->msg_printf(g.wt_api, session, "%-10s{%.*s}\n%-10s{%.*s}", "putK", (int)key->size, (char *)key->data, "putV", (int)value->size, (char *)value->data); cursor->set_key(cursor, key); cursor->set_value(cursor, value); ret = cursor->update(cursor); if (ret == WT_ROLLBACK) return (WT_ROLLBACK); if (ret != 0 && ret != WT_NOTFOUND) testutil_die(ret, "row_update: update row %" PRIu64 " by key", keyno); #ifdef HAVE_BERKELEY_DB if (!SINGLETHREADED) return (0); { int notfound; bdb_update(key->data, key->size, value->data, value->size, ¬found); (void)notfound_chk("row_update", ret, notfound, keyno); } #endif return (0); }
/* * nextprev -- * Read and verify the next/prev element in a row- or column-store file. */ static int nextprev(WT_CURSOR *cursor, int next, int *notfoundp) { WT_ITEM key, value; uint64_t keyno; int ret; uint8_t bitfield; const char *which; which = next ? "next" : "prev"; keyno = 0; ret = next ? cursor->next(cursor) : cursor->prev(cursor); if (ret == WT_ROLLBACK) return (WT_ROLLBACK); if (ret == 0) switch (g.type) { case FIX: if ((ret = cursor->get_key(cursor, &keyno)) == 0 && (ret = cursor->get_value(cursor, &bitfield)) == 0) { value.data = &bitfield; value.size = 1; } break; case ROW: if ((ret = cursor->get_key(cursor, &key)) == 0) ret = cursor->get_value(cursor, &value); break; case VAR: if ((ret = cursor->get_key(cursor, &keyno)) == 0) ret = cursor->get_value(cursor, &value); break; } if (ret != 0 && ret != WT_NOTFOUND) die(ret, "%s", which); *notfoundp = (ret == WT_NOTFOUND); #ifdef HAVE_BERKELEY_DB if (!SINGLETHREADED) return (0); { WT_ITEM bdb_key, bdb_value; WT_SESSION *session; int notfound; char *p; session = cursor->session; /* Retrieve the BDB value. */ bdb_np(next, &bdb_key.data, &bdb_key.size, &bdb_value.data, &bdb_value.size, ¬found); if (notfound_chk( next ? "nextprev(next)" : "nextprev(prev)", ret, notfound, keyno)) return (0); /* Compare the two. */ if (g.type == ROW) { if (key.size != bdb_key.size || memcmp(key.data, bdb_key.data, key.size) != 0) { fprintf(stderr, "nextprev: %s key mismatch:\n", which); print_item("bdb-key", &bdb_key); print_item(" wt-key", &key); die(0, NULL); } } else { if (keyno != (uint64_t)atoll(bdb_key.data)) { if ((p = strchr((char *)bdb_key.data, '.')) != NULL) *p = '\0'; fprintf(stderr, "nextprev: %s key mismatch: %.*s != %" PRIu64 "\n", which, (int)bdb_key.size, (char *)bdb_key.data, keyno); die(0, NULL); } } if (value.size != bdb_value.size || memcmp(value.data, bdb_value.data, value.size) != 0) { fprintf(stderr, "nextprev: %s value mismatch:\n", which); print_item("bdb-value", &bdb_value); print_item(" wt-value", &value); die(0, NULL); } if (g.logging == LOG_OPS) switch (g.type) { case FIX: (void)g.wt_api->msg_printf(g.wt_api, session, "%-10s%" PRIu64 " {0x%02x}", which, keyno, ((char *)value.data)[0]); break; case ROW: (void)g.wt_api->msg_printf( g.wt_api, session, "%-10s{%.*s/%.*s}", which, (int)key.size, (char *)key.data, (int)value.size, (char *)value.data); break; case VAR: (void)g.wt_api->msg_printf(g.wt_api, session, "%-10s%" PRIu64 " {%.*s}", which, keyno, (int)value.size, (char *)value.data); break; } } #endif return (0); }
/* * read_row -- * Read and verify a single element in a row- or column-store file. */ static int read_row(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno) { static int sn = 0; WT_ITEM value; WT_SESSION *session; int exact, ret; uint8_t bitfield; session = cursor->session; /* Log the operation */ if (g.logging == LOG_OPS) (void)g.wt_api->msg_printf(g.wt_api, session, "%-10s%" PRIu64, "read", keyno); /* Retrieve the key/value pair by key. */ switch (g.type) { case FIX: case VAR: cursor->set_key(cursor, keyno); break; case ROW: key_gen((uint8_t *)key->data, &key->size, keyno); cursor->set_key(cursor, key); break; } if (sn) { ret = cursor->search_near(cursor, &exact); if (ret == 0 && exact != 0) ret = WT_NOTFOUND; sn = 0; } else { ret = cursor->search(cursor); sn = 1; } if (ret == 0) { if (g.type == FIX) { ret = cursor->get_value(cursor, &bitfield); value.data = &bitfield; value.size = 1; } else { ret = cursor->get_value(cursor, &value); } } if (ret == WT_ROLLBACK) return (WT_ROLLBACK); if (ret != 0 && ret != WT_NOTFOUND) die(ret, "read_row: read row %" PRIu64, keyno); #ifdef HAVE_BERKELEY_DB if (!SINGLETHREADED) return (0); /* * In fixed length stores, zero values at the end of the key space are * returned as not found. Treat this the same as a zero value in the * key space, to match BDB's behavior. */ if (ret == WT_NOTFOUND && g.type == FIX) { bitfield = 0; value.data = &bitfield; value.size = 1; ret = 0; } /* Retrieve the BDB value. */ { WT_ITEM bdb_value; int notfound; bdb_read(keyno, &bdb_value.data, &bdb_value.size, ¬found); /* Check for not-found status. */ if (notfound_chk("read_row", ret, notfound, keyno)) return (0); /* Compare the two. */ if (value.size != bdb_value.size || memcmp(value.data, bdb_value.data, value.size) != 0) { fprintf(stderr, "read_row: value mismatch %" PRIu64 ":\n", keyno); print_item("bdb", &bdb_value); print_item(" wt", &value); die(0, NULL); } } #endif return (0); }
/* * read_row -- * Read and verify a single element in a row- or column-store file. */ static void read_row(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno) { WT_ITEM bdb_value, value; WT_SESSION *session; int notfound, ret; uint8_t bitfield; session = cursor->session; /* Log the operation */ if (g.logging == LOG_OPS) (void)session->msg_printf( session, "%-10s%" PRIu64, "read", keyno); /* Retrieve the key/value pair by key. */ switch (g.c_file_type) { case FIX: case VAR: cursor->set_key(cursor, keyno); break; case ROW: key_gen((uint8_t *)key->data, &key->size, keyno, 0); cursor->set_key(cursor, key); break; } if ((ret = cursor->search(cursor)) == 0) { if (g.c_file_type == FIX) { ret = cursor->get_value(cursor, &bitfield); value.data = &bitfield; value.size = 1; } else { memset(&value, 0, sizeof(value)); ret = cursor->get_value(cursor, &value); } } if (ret != 0 && ret != WT_NOTFOUND) die(ret, "read_row: read row %" PRIu64, keyno); if (!SINGLETHREADED) return; /* Retrieve the BDB value. */ memset(&bdb_value, 0, sizeof(bdb_value)); bdb_read(keyno, &bdb_value.data, &bdb_value.size, ¬found); /* * Check for not-found status. * * In fixed length stores, zero values at the end of the key space * are treated as not found. Treat this the same as a zero value * in the key space, to match BDB's behavior. */ if (g.c_file_type == FIX && ret == WT_NOTFOUND) { bitfield = 0; ret = 0; } if (notfound_chk("read_row", ret, notfound, keyno)) return; /* Compare the two. */ if (value.size != bdb_value.size || memcmp(value.data, bdb_value.data, value.size) != 0) { fprintf(stderr, "read_row: read row value mismatch %" PRIu64 ":\n", keyno); print_item("bdb", &bdb_value); print_item(" wt", &value); die(0, NULL); } }