Added flags to get function.
This commit is contained in:
parent
13d1174bb5
commit
332e18e7be
2 changed files with 33 additions and 19 deletions
|
@ -618,7 +618,10 @@ static void do_async_put_free(void* arg)
|
||||||
static void do_async_get(void* arg)
|
static void do_async_get(void* arg)
|
||||||
{
|
{
|
||||||
printf("do_async_get\n");
|
printf("do_async_get\n");
|
||||||
|
|
||||||
|
// Payload is: << DbRef:32, Flags:32, KeyLen:32, Key:KeyLen >>
|
||||||
AsyncData* adata = (AsyncData*)arg;
|
AsyncData* adata = (AsyncData*)arg;
|
||||||
|
unsigned flags = UNPACK_INT(adata->payload, 4);
|
||||||
|
|
||||||
// Setup DBTs
|
// Setup DBTs
|
||||||
DBT key;
|
DBT key;
|
||||||
|
@ -627,9 +630,8 @@ static void do_async_get(void* arg)
|
||||||
memset(&value, '\0', sizeof(DBT));
|
memset(&value, '\0', sizeof(DBT));
|
||||||
|
|
||||||
// Parse payload into DBT
|
// Parse payload into DBT
|
||||||
// Payload is: << DbRef:32, KeyLen:32, Key:KeyLen >>
|
key.size = UNPACK_INT(adata->payload, 8);
|
||||||
key.size = *((int*)(adata->payload + 4));
|
key.data = UNPACK_BLOB(adata->payload, 12);
|
||||||
key.data = (void*)(adata->payload + 8);
|
|
||||||
|
|
||||||
// Allocate memory to hold the value -- hard code initial size to 4k
|
// Allocate memory to hold the value -- hard code initial size to 4k
|
||||||
// TODO: Make this smarter!
|
// TODO: Make this smarter!
|
||||||
|
@ -637,13 +639,13 @@ static void do_async_get(void* arg)
|
||||||
value.ulen = 4096;
|
value.ulen = 4096;
|
||||||
value.flags = DB_DBT_USERMEM;
|
value.flags = DB_DBT_USERMEM;
|
||||||
|
|
||||||
int rc = adata->db->get(adata->db, adata->port->txn, &key, &value, 0);
|
int rc = adata->db->get(adata->db, adata->port->txn, &key, &value, flags);
|
||||||
while (rc == DB_BUFFER_SMALL)
|
while (rc == DB_BUFFER_SMALL)
|
||||||
{
|
{
|
||||||
// Grow our value buffer and try again
|
// Grow our value buffer and try again
|
||||||
value.data = driver_realloc(value.data, value.size);
|
value.data = driver_realloc(value.data, value.size);
|
||||||
value.ulen = value.size;
|
value.ulen = value.size;
|
||||||
rc = adata->db->get(adata->db, adata->port->txn, &key, &value, 0);
|
rc = adata->db->get(adata->db, adata->port->txn, &key, &value, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
adata->payload = value.data;
|
adata->payload = value.data;
|
||||||
|
|
|
@ -337,10 +337,13 @@ put(Port, DbRef, Key, Value, Opts) ->
|
||||||
?ERROR_INVALID_DBREF -> {error, invalid_dbref}
|
?ERROR_INVALID_DBREF -> {error, invalid_dbref}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
get(Port, DbRef, Key) ->
|
get(Port, DbRef, Key) ->
|
||||||
|
get(Port, DbRef, Key, []).
|
||||||
|
|
||||||
|
get(Port, DbRef, Key, Opts) ->
|
||||||
{KeyLen, KeyBin} = to_binary(Key),
|
{KeyLen, KeyBin} = to_binary(Key),
|
||||||
Cmd = <<DbRef:32/native, KeyLen:32/native, KeyBin/bytes>>,
|
Flags = process_flags(Opts),
|
||||||
|
Cmd = <<DbRef:32/native, Flags:32/unsigned-native, KeyLen:32/native, KeyBin/bytes>>,
|
||||||
<<Result:32/native>> = erlang:port_control(Port, ?CMD_GET, Cmd),
|
<<Result:32/native>> = erlang:port_control(Port, ?CMD_GET, Cmd),
|
||||||
case Result of
|
case Result of
|
||||||
?ERROR_NONE ->
|
?ERROR_NONE ->
|
||||||
|
@ -365,16 +368,25 @@ process_flags([Flag|Flags]) ->
|
||||||
|
|
||||||
flag_value(Flag) ->
|
flag_value(Flag) ->
|
||||||
case Flag of
|
case Flag of
|
||||||
append -> ?DB_APPEND;
|
append -> ?DB_APPEND;
|
||||||
auto_commit -> ?DB_AUTO_COMMIT;
|
auto_commit -> ?DB_AUTO_COMMIT;
|
||||||
create -> ?DB_CREATE;
|
consume -> ?DB_CONSUME;
|
||||||
exclusive -> ?DB_EXCL;
|
consume_wait -> ?DB_CONSUME_WAIT;
|
||||||
multiversion -> ?DB_MULTIVERSION;
|
create -> ?DB_CREATE;
|
||||||
no_duplicate -> ?DB_NODUPDATA;
|
exclusive -> ?DB_EXCL;
|
||||||
no_mmap -> ?DB_NOMMAP;
|
get_both -> ?DB_GET_BOTH;
|
||||||
no_overwrite -> ?DB_NOOVERWRITE;
|
ignore_lease -> ?DB_IGNORE_LEASE;
|
||||||
no_sync -> ?DB_NOSYNC;
|
multiple -> ?DB_MULTIPLE;
|
||||||
readonly -> ?DB_RDONLY;
|
multiversion -> ?DB_MULTIVERSION;
|
||||||
threaded -> ?DB_THREAD;
|
no_duplicate -> ?DB_NODUPDATA;
|
||||||
truncate -> ?DB_TRUNCATE
|
no_mmap -> ?DB_NOMMAP;
|
||||||
|
no_overwrite -> ?DB_NOOVERWRITE;
|
||||||
|
no_sync -> ?DB_NOSYNC;
|
||||||
|
read_committed -> ?DB_READ_COMMITTED;
|
||||||
|
read_uncommitted -> ?DB_READ_UNCOMMITTED;
|
||||||
|
readonly -> ?DB_RDONLY;
|
||||||
|
rmw -> ?DB_RMW;
|
||||||
|
set_recno -> ?DB_SET_RECNO;
|
||||||
|
threaded -> ?DB_THREAD;
|
||||||
|
truncate -> ?DB_TRUNCATE
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in a new issue