Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADDED] KeyValue: kvStatus_Bytes() to return size of the bucket #595

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/kv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,12 @@ kvStatus_Replicas(kvStatus *sts)
return (sts == NULL || sts->si->Config == NULL ? 0 : sts->si->Config->Replicas);
}

uint64_t
kvStatus_Bytes(kvStatus *sts)
{
return (sts == NULL ? 0 : sts->si->State.Bytes);
}

void
kvStatus_Destroy(kvStatus *sts)
{
Expand Down
9 changes: 9 additions & 0 deletions src/nats.h
Original file line number Diff line number Diff line change
Expand Up @@ -7028,6 +7028,15 @@ kvStatus_TTL(kvStatus *sts);
NATS_EXTERN int64_t
kvStatus_Replicas(kvStatus *sts);

/** \brief Returns the size (in bytes) of this bucket.
*
* Returns the size (in bytes) of this bucket, or `0` if `sts` itself is `NULL`.
*
* @param sts the pointer to the #kvStatus object.
*/
NATS_EXTERN uint64_t
kvStatus_Bytes(kvStatus *sts);

/** \brief Destroys the KeyValue status object.
*
* Releases memory allocated for this #kvStatus object.
Expand Down
24 changes: 23 additions & 1 deletion test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -29538,6 +29538,13 @@ test_KeyValueBasics(void)
s = (kvStore_Bucket(NULL) == NULL ? NATS_OK : NATS_ERR);
testCond(s == NATS_OK);

test("Check bytes is 0: ");
s = kvStore_Status(&sts, kv);
IFOK(s, (kvStatus_Bytes(sts) == 0 ? NATS_OK : NATS_ERR));
testCond(s == NATS_OK);
kvStatus_Destroy(sts);
sts = NULL;

test("Simple put (bad args): ");
rev = 1234;
s = kvStore_Put(&rev, NULL, "key", (const void*) "value", 5);
Expand Down Expand Up @@ -29763,9 +29770,24 @@ test_KeyValueBasics(void)
s = (kvStatus_Replicas(sts) == 1 ? NATS_OK : NATS_ERR);
testCond(s == NATS_OK);

test("Check bytes: ");
{
jsStreamInfo *si = NULL;

if (i == 0)
s = js_GetStreamInfo(&si, js, "KV_TEST0", NULL, NULL);
else
s = js_GetStreamInfo(&si, js, "KV_TEST1", NULL, NULL);
IFOK(s, (kvStatus_Bytes(sts) == si->State.Bytes ? NATS_OK : NATS_ERR));

jsStreamInfo_Destroy(si);
}
testCond(s == NATS_OK);

test("Check status with NULL: ");
if ((kvStatus_History(NULL) != 0) || (kvStatus_Bucket(NULL) != NULL)
|| (kvStatus_TTL(NULL) != 0) || (kvStatus_Values(NULL) != 0))
|| (kvStatus_TTL(NULL) != 0) || (kvStatus_Values(NULL) != 0)
|| (kvStatus_Bytes(NULL) != 0))
{
s = NATS_ERR;
}
Expand Down