Some thoughts on misc "getpart" implementation

3 views
Skip to first unread message

Łukasz Osipiuk

unread,
Nov 20, 2009, 8:30:56 AM11/20/09
to Tokyo Cabinet Users, Mikio Hirabayashi
Hi,

As I noticed 1.4.37 version of cabinet added new misc function
getpart. About the same time I created patch for TT adding the same
functionality. Below I propose some (I believe) improvements for this
functionality.

1. getpart returns an error in case caller specifies offset greater
than value's length. I believe it is more user friendly to return
empty value in such case if requested key is present in database.
Often caller does not know the real length of stored value, and
getting this length from tt is not efficient.

2. Caller cannot distinguish between error caused by inexistent key
and other problem; as function always returns miscerror 9999. This
sucks - especially until point 1. is fixed. In case key is not present
in
db caller should get TTENOREC as when calling simple get.

3. As function is implemented in tc (not in tt) it would be much more
efficient to read from disk only requested part of value - I do not
know if it is easy to do but would be great feature for me, as I store
large values in tc and usually need to read only parts of them.

4. following code snippet from implementation look awkward:
if(off < 0) off = 0;
if(off > INT_MAX / 2 - 1) off = INT_MAX - 1;
int len = argc > 2 ? tcatoi(TCLISTVALPTR(args, 2)) : -1;
if(len < 0 || len > INT_MAX / 2) len = INT_MAX / 2;

should not offset be set off = INT_MAX / 2 - 1?
I do not really know which values should be used but above code look
strangely unsymmetrical :)

PS. Mikio, I am cc-ing you directly as I am not sure you are member of
this group

Regards, Łukasz Osipiuk
Reply all
Reply to author
Forward
0 new messages