KISSDB_get always failing when failed once
Opened this issue · 0 comments
noeldum commented
Working on a multiple access database. If a call to KISSDB_get fails as the key does not exists yet then that call will always fails even though the key has been written by another process.
Not sure if this is a bug or an expected behaviour. My work around for now is to close and reopen the db.
I wrote these two codes to illustrate this. A and B. On an existing db run A which should say fail as the key 100 does not exists. While A runs run B to write the key 100. A will still say fail. Close A and relaunch. It will now find the key.
A
#include <stdio.h>
#include "kissdb.h"
#include <inttypes.h>
#include <signal.h>
#include <unistd.h>
static volatile int keepRunning = 1;
void intHandler(int dummy) {
keepRunning = 0;
}
int main(int argc, char *argv[]){
KISSDB db;
uint64_t paquets[2];
uint64_t key = 100;
KISSDB_open(&db,"test.db",KISSDB_OPEN_MODE_RDWR,1024,8,sizeof(paquets));
while (1){
if (KISSDB_get(&db, &key, paquets)) printf("fails\n");
else printf("ok\n");
sleep(2);
}
}
B
#include <stdio.h>
#include "kissdb.h"
#include <inttypes.h>
#include <signal.h>
#include <unistd.h>
static volatile int keepRunning = 1;
void intHandler(int dummy) {
keepRunning = 0;
}
int main(int argc, char *argv[]){
KISSDB db;
uint64_t paquets[2];
uint64_t key = 100;
KISSDB_open(&db,"test.db",KISSDB_OPEN_MODE_RWCREAT,1024,8,sizeof(paquets));
KISSDB_put(&db, &key, paquets);
KISSDB_close(&db);
}