Skip to content

Commit bf5d108

Browse files
committed
{173778048} bdb_count should be able to count tables w no indices
Signed-off-by: Salil Chandra <schandra107@bloomberg.net>
1 parent 88f20eb commit bf5d108

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

bdb/bdb_cursor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ int bdb_get_lsn_context_from_timestamp(bdb_state_type *bdb_state,
199199
int bdb_get_context_from_lsn(bdb_state_type *bdb_state, void *lsnp,
200200
unsigned long long *ret_context, int *bdberr);
201201

202-
int bdb_direct_count(bdb_cursor_ifn_t *, int ixnum, int64_t *count, int is_snapcur, uint32_t last_commit_lsn_file, uint32_t last_commit_lsn_offset, uint32_t last_checkpoint_lsn_file, uint32_t last_checkpoint_lsn_offset);
202+
int bdb_direct_count_int(bdb_state_type *state, int ixnum, int64_t *rcnt, int is_snapcur, uint32_t modsnap_start_lsn_file, uint32_t modsnap_start_lsn_offset, uint32_t last_checkpoint_lsn_file, uint32_t last_checkpoint_lsn_offset, int parallel_count);
203+
int bdb_direct_count(bdb_cursor_ifn_t *cur, int ixnum, int64_t *rcnt, int is_snapcur, uint32_t modsnap_start_lsn_file, uint32_t modsnap_start_lsn_offset, uint32_t last_checkpoint_lsn_file, uint32_t last_checkpoint_lsn_offset);
203204

204205
#endif

bdb/count.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ int bdb_count_int(bdb_state_type *bdb_state, int *bdberr)
208208
return -1;
209209
}
210210

211+
// TODO: We are not using the smallest index here, why? We are using ix0
211212
rc = bdb_state->dbp_ix[0]->cursor(bdb_state->dbp_ix[0], 0, &dbcp, 0);
212213
if (rc != 0) {
213214
myfree(buffer);
@@ -300,7 +301,13 @@ int bdb_count(bdb_state_type *bdb_state, int *bdberr)
300301
int ret;
301302
BDB_READLOCK("bdb_count");
302303

303-
ret = bdb_count_int(bdb_state, bdberr);
304+
// ret = bdb_count_int(bdb_state, bdberr);
305+
int64_t count;
306+
// bdb_count_int would use ix 0 if available, do the same thing here
307+
ret = bdb_direct_count_int(bdb_state, bdb_state->numix > 0 ? 0 : -1, &count, 0, 0, 0, 0, 0, 0);
304308
BDB_RELLOCK();
305-
return ret;
309+
if (ret == 0)
310+
return count;
311+
*bdberr = (ret == BDBERR_DEADLOCK ? ret : BDBERR_MISC);
312+
return -1;
306313
}

bdb/cursor.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7454,19 +7454,15 @@ static void *db_count(void *varg)
74547454
return NULL;
74557455
}
74567456

7457-
int gbl_parallel_count = 0;
7458-
int bdb_direct_count(bdb_cursor_ifn_t *cur, int ixnum, int64_t *rcnt, int is_snapcur, uint32_t modsnap_start_lsn_file, uint32_t modsnap_start_lsn_offset, uint32_t last_checkpoint_lsn_file, uint32_t last_checkpoint_lsn_offset)
7457+
int bdb_direct_count_int(bdb_state_type *state, int ixnum, int64_t *rcnt, int is_snapcur, uint32_t modsnap_start_lsn_file, uint32_t modsnap_start_lsn_offset, uint32_t last_checkpoint_lsn_file, uint32_t last_checkpoint_lsn_offset, int parallel_count)
74597458
{
74607459
int64_t count = 0;
7461-
int parallel_count;
7462-
bdb_state_type *state = cur->impl->state;
74637460
DB **db;
74647461
int stripes;
74657462
pthread_attr_t attr;
74667463
if (ixnum < 0) { // data
74677464
db = state->dbp_data[0];
74687465
stripes = state->attr->dtastripe;
7469-
parallel_count = gbl_parallel_count;
74707466
Pthread_attr_init(&attr);
74717467
#ifdef PTHREAD_STACK_MIN
74727468
Pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + 512 * 1024);
@@ -7516,3 +7512,9 @@ int bdb_direct_count(bdb_cursor_ifn_t *cur, int ixnum, int64_t *rcnt, int is_sna
75167512
if (rc == 0) *rcnt = count;
75177513
return rc;
75187514
}
7515+
7516+
int gbl_parallel_count = 0;
7517+
int bdb_direct_count(bdb_cursor_ifn_t *cur, int ixnum, int64_t *rcnt, int is_snapcur, uint32_t modsnap_start_lsn_file, uint32_t modsnap_start_lsn_offset, uint32_t last_checkpoint_lsn_file, uint32_t last_checkpoint_lsn_offset)
7518+
{
7519+
return bdb_direct_count_int(cur->impl->state, ixnum, rcnt, is_snapcur, modsnap_start_lsn_file, modsnap_start_lsn_offset, last_checkpoint_lsn_file, last_checkpoint_lsn_offset, gbl_parallel_count);
7520+
}

0 commit comments

Comments
 (0)