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

Fix crc64_init_thread_safe() #24

Merged
merged 3 commits into from
Oct 19, 2023
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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,18 @@ destruction, or when newer block replacing old one.

Usage: rdb-cli /path/to/dump.rdb [OPTIONS] {json|resp|redis} [FORMAT_OPTIONS]
OPTIONS:
-l, --log-file {<PATH>|-} Path to the log file or stdout (Default: './rdb-cli.log')
-l, --log-file <PATH> Path to the log file or stdout (Default: './rdb-cli.log')

Multiple filters combination of keys/types/dbs can be specified:
Multiple filters combination of keys/types/dbs can be specified:
-k, --key <REGEX> Include only keys that match REGEX
-K --no-key <REGEX> Exclude keys that match REGEX
-K --no-key <REGEX> Exclude all keys that match REGEX
-t, --type <TYPE> Include only selected TYPE {str|list|set|zset|hash|module|func}
-T, --no-type <TYPE> Exclude TYPE {str|list|set|zset|hash|module|func}
-d, --dbnum <DBNUM> Include only selected db number
-D, --no-dbnum <DBNUM> Exclude DB number

FORMAT_OPTIONS ('json'):
-i, --include <EXTRAS> To include: {aux-val|func}
-i, --include <EXTRAS> To include: {aux-val|func|stream-meta}
-f, --flatten Print flatten json, without DBs Parenthesis
-o, --output <FILE> Specify the output file. If not specified, output to stdout

Expand All @@ -238,6 +238,7 @@ destruction, or when newer block replacing old one.
-e, --enum-commands Command enumeration and tracing by preceding each generated RESP command
with debug command of type: `SET _RDB_CLI_CMD_ID_ <CMD-ID>`


<a name="Advanced"></a>
## Advanced
### Customized Reader
Expand Down
11 changes: 5 additions & 6 deletions deps/redis/crc64.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,13 @@ uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l) {
void crc64_init_thread_safe(void) {
static int crcInitalized = 0;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

pthread_mutex_lock(&mutex);
if (!crcInitalized) {
pthread_mutex_lock(&mutex);
if (!crcInitalized) {
crc64_init();
crcInitalized = 1;
}
pthread_mutex_unlock(&mutex);
crc64_init();
crcInitalized = 1;
}
pthread_mutex_unlock(&mutex);
}

/* Test main */
Expand Down
8 changes: 4 additions & 4 deletions src/lib/parserRaw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,16 +1166,16 @@ static RdbStatus aggMakeRoom(RdbParser *p, size_t numBytesRq) {
BulkInfo *currBuff = ctx->bulkArray + ctx->curBulkIndex;
size_t freeRoomLeft = currBuff->len - currBuff->written;

/* fill-up current buffer before attempting to allocate new one */
if (likely(freeRoomLeft >= numBytesRq))
return RDB_STATUS_OK;

if (unlikely(p->maxRawSize < ctx->totalSize + numBytesRq)) {
RDB_reportError(p, RDB_ERR_MAX_RAW_LEN_EXCEEDED_FOR_KEY, "Maximum raw length exceeded for key (len=%lu)",
ctx->totalSize + numBytesRq);
return RDB_STATUS_ERROR;
}

/* fill-up current buffer before attempting to allocate new one */
if (likely(freeRoomLeft >= numBytesRq))
return RDB_STATUS_OK;

/* determine next buffer size to allocate. Factor x2 up-to 1mb, x1.5 upto
* 256mb, or x1.2 above it. With 96 entries for bulkArray, it is sufficient
* for at least 100TB */
Expand Down