Skip to content

Commit 6c0ef4c

Browse files
authored
Merge pull request #78 from DCSO/fixes-and-improvements
Various fixes and improvements
2 parents f421b10 + c14d975 commit 6c0ef4c

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

backend/balboa-backend-console/main.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// balboa
2-
// Copyright (c) 2019, 2020, DCSO GmbH
2+
// Copyright (c) 2019, 2026, DCSO GmbH
33

44
#include <arpa/inet.h>
55
#include <assert.h>
@@ -177,6 +177,7 @@ static int main_query(int argc, char** argv) {
177177
case 'v': trace_config.verbosity += 1; break;
178178
case 'h': engine_config.host = opt.arg; break;
179179
case 'p': engine_config.port = atoi(opt.arg); break;
180+
case 'l': query->limit = atoi(opt.arg); break;
180181
case 'd':
181182
if(opt.arg == NULL) {
182183
L(log_emergency("string for option `-d` required"));
@@ -365,6 +366,17 @@ Command dump:\n\
365366
-v increase verbosity; can be passed multiple times\n\
366367
-d <remote-dump-path> unused/ignored (default: -)\n\
367368
\n\
369+
Command query:\n\
370+
execute a query against the database\n\
371+
\n\
372+
-h <host> ip address of the `balboa-backend` (default: 127.0.0.1)\n\
373+
-p <port> port of the `balboa-backend` (default: 4242)\n\
374+
-r <rrname> rrname to query for\n\
375+
-d <rdata> rdata to query for\n\
376+
-s <sensorid> sensorid to filter by\n\
377+
-l <limit> maximum number of results (default: 100)\n\
378+
-v increase verbosity; can be passed multiple times\n\
379+
\n\
368380
Command replay:\n\
369381
replay a previously generated database dump\n\
370382
\n\
@@ -530,4 +542,4 @@ int main(int argc, char** argv) {
530542
}
531543

532544
return (res);
533-
}
545+
}

backend/balboa-rocksdb/rocksdb-impl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// balboa
2-
// Copyright (c) 2018, 2019 DCSO GmbH
2+
// Copyright (c) 2018, 2026 DCSO GmbH
33

44
#include <stdio.h>
55
#include <stdlib.h>
@@ -467,6 +467,10 @@ static int blb_rocksdb_query_by_i(
467467
keys_visited += 1;
468468
size_t key_len = 0;
469469
const char* key = rocksdb_iter_key(it, &key_len);
470+
if(key_len < prefix_len
471+
|| memcmp(key, dbc->scrtch_inv, prefix_len) != 0) {
472+
break;
473+
}
470474
char* err = NULL;
471475

472476
enum TokIdx { RDATA = 3, SENSORID = 2, RRNAME = 1, RRTYPE = 0, FIELDS = 4 };

backend/lib/alloc.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// balboa
2-
// Copyright (c) 2018, 2019 DCSO GmbH
2+
// Copyright (c) 2018, 2026 DCSO GmbH
33

44
#ifndef __ALLOC_H
55
#define __ALLOC_H
@@ -10,8 +10,10 @@
1010

1111
static inline void* blb_realloc_impl(
1212
const char* name, void* p, size_t new_size) {
13+
uintptr_t old_addr = (uintptr_t)p;
1314
void* pp = realloc(p, new_size);
14-
X(log_debug("(%s) realloc `%p` `%p` `%zu`", name, p, pp, new_size));
15+
X(log_debug(
16+
"(%s) realloc `0x%" PRIxPTR "` `%p` `%zu`", name, old_addr, pp, new_size));
1517
return (pp);
1618
}
1719

@@ -32,8 +34,9 @@ static inline void* blb_realloc_impl(
3234
#define blb_realloc(p, sz) \
3335
({ \
3436
size_t p_sz = (sz); \
37+
uintptr_t old_addr = (uintptr_t)(p); \
3538
void* pp = realloc((p), p_sz); \
36-
X(log_debug("realloc `%p` `%zu` `%p`", pp, p_sz, p)); \
39+
X(log_debug("realloc `0x%" PRIxPTR "` `%zu` `%p`", old_addr, p_sz, pp)); \
3740
pp; \
3841
})
3942
#define blb_free(p) \
@@ -42,4 +45,4 @@ static inline void* blb_realloc_impl(
4245
free(p); \
4346
} while(0)
4447

45-
#endif
48+
#endif

0 commit comments

Comments
 (0)