Skip to content

Commit

Permalink
db: add api to create tdb entry without unwanted copying
Browse files Browse the repository at this point in the history
fix #690
  • Loading branch information
vankoven committed Jun 8, 2017
1 parent 0243633 commit d9f5442
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
3 changes: 2 additions & 1 deletion tempesta_db/core/htrie.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ tdb_htrie_create_rec(TdbHdr *dbh, unsigned long off, unsigned long key,
} else {
ptr += sizeof(TdbFRec);
}
memcpy(ptr, data, len);
if (data)
memcpy(ptr, data, len);

return r;
}
Expand Down
21 changes: 19 additions & 2 deletions tempesta_db/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This is the entry point: initialization functions and public interfaces.
*
* Copyright (C) 2014 NatSys Lab. (info@natsys-lab.com).
* Copyright (C) 2015 Tempesta Technologies, Inc.
* Copyright (C) 2015 - 2017 Tempesta Technologies, Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
Expand All @@ -28,13 +28,16 @@
#include "table.h"
#include "tdb_if.h"

#define TDB_VERSION "0.1.15"
#define TDB_VERSION "0.1.16"

MODULE_AUTHOR("Tempesta Technologies");
MODULE_DESCRIPTION("Tempesta DB");
MODULE_VERSION(TDB_VERSION);
MODULE_LICENSE("GPL");

/**
* Create TDB entry and copy @len contigious bytes from @data to the entry.
*/
TdbRec *
tdb_entry_create(TDB *db, unsigned long key, void *data, size_t *len)
{
Expand All @@ -47,6 +50,20 @@ tdb_entry_create(TDB *db, unsigned long key, void *data, size_t *len)
}
EXPORT_SYMBOL(tdb_entry_create);

/**
* Create TDB entry to store @len bytes.
*/
TdbRec *
tdb_entry_alloc(TDB *db, unsigned long key, size_t *len)
{
TdbRec *r = tdb_htrie_insert(db->hdr, key, NULL, len);
if (!r)
TDB_ERR("Cannot create cache entry for key=%#lx\n", key);

return r;
}
EXPORT_SYMBOL(tdb_entry_alloc);

/**
* @return pointer to free area of size at least @size bytes or allocate
* a new record and link it with the current one.
Expand Down
3 changes: 2 additions & 1 deletion tempesta_db/core/tdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Generic storage layer.
*
* Copyright (C) 2014 NatSys Lab. (info@natsys-lab.com).
* Copyright (C) 2015-2016 Tempesta Technologies.
* Copyright (C) 2015-2017 Tempesta Technologies.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -161,6 +161,7 @@ typedef struct {
/*
* Storage routines.
*/
TdbRec *tdb_entry_alloc(TDB *db, unsigned long key, size_t *len);
TdbRec *tdb_entry_create(TDB *db, unsigned long key, void *data, size_t *len);
TdbVRec *tdb_entry_add(TDB *db, TdbVRec *r, size_t size);
void *tdb_entry_get_room(TDB *db, TdbVRec **r, char *curr_ptr, size_t tail_len,
Expand Down
6 changes: 3 additions & 3 deletions tempesta_fw/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ static void
__cache_add_node(TDB *db, TfwHttpResp *resp, TfwHttpReq *req,
unsigned long key)
{
TfwCacheEntry *ce, cdata = {{}};
TfwCacheEntry *ce;
size_t data_len = __cache_entry_size(resp, req);
size_t len = data_len;

Expand All @@ -861,8 +861,8 @@ __cache_add_node(TDB *db, TfwHttpResp *resp, TfwHttpReq *req,
* TDB should provide enough space to place at least head of
* the record key at first chunk.
*/
ce = (TfwCacheEntry *)tdb_entry_create(db, key, &cdata.ce_body, &len);
BUG_ON(len <= sizeof(cdata));
ce = (TfwCacheEntry *)tdb_entry_alloc(db, key, &len);
BUG_ON(len <= sizeof(TfwCacheEntry));
if (!ce)
return;

Expand Down

0 comments on commit d9f5442

Please sign in to comment.