lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


K; Sounds like good advice; thanks, Sam.

To answer your questions re manipulating these timestamps, though:
I don't think they require much (or any) manipulation.

This is probably overkill, but here are the prototypes I am looking at:

/* Restore the database file of a remote database object from the update log.
   `rdb' specifies the remote database object.
   `path' specifies the path of the update log directory.
   `ts' specifies the beginning timestamp in microseconds.
   `opts' specifies options by bitwise-or: `RDBROCHKCON' for consistency checking.
   If successful, the return value is true, else, it is false. */
bool tcrdbrestore(TCRDB *rdb, const char *path, uint64_t ts, int opts);

/* Set the replication master of a remote database object.
   `rdb' specifies the remote database object.
   `host' specifies the name or the address of the server.  If it is `NULL', replication of the
   database is disabled.
   `port' specifies the port number.
   `ts' specifies the beginning timestamp in microseconds.
   `opts' specifies options by bitwise-or: `RDBROCHKCON' for consistency checking.
   If successful, the return value is true, else, it is false. */
bool tcrdbsetmst(TCRDB *rdb, const char *host, int port, uint64_t ts, int opts);

/* Set the replication master of a remote database object with a simple server _expression_.
   `rdb' specifies the remote database object.
   `expr' specifies the simple server _expression_.  It is composed of two substrings separated
   by ":".  The former field specifies the name or the address of the server.  The latter field
   specifies the port number.  If the latter field is omitted, the default port number is
   specified.
   `ts' specifies the beginning timestamp in microseconds.
   `opts' specifies options by bitwise-or: `RDBROCHKCON' for consistency checking.
   If successful, the return value is true, else, it is false. */
bool tcrdbsetmst2(TCRDB *rdb, const char *expr, uint64_t ts, int opts);

/* Get the number of records of a remote database object.
   `rdb' specifies the remote database object.
   The return value is the number of records or 0 if the object does not connect to any database
   server. */
uint64_t tcrdbrnum(TCRDB *rdb);

/* Get the size of the database of a remote database object.
   `rdb' specifies the remote database object.
   The return value is the size of the database or 0 if the object does not connect to any
   database server. */
uint64_t tcrdbsize(TCRDB *rdb);


Phoenix Sol


On Wed, Jul 8, 2009 at 3:02 PM, Sam Roberts <vieuxtech@gmail.com> wrote:
On Wed, Jul 8, 2009 at 12:47 PM, Phoenix Sol<phoenix@burninglabs.com> wrote:
> Aha; Thanks, Fabio.
>
> So then I need to wrap those C functions with my own, correct?
> ( I'm still pretty ignorant of C, unfortunately... I wonder if I can do an
> implicit conversion, and 'shoe-horn' longs in there? I'm about to try it,
> but do please reply if you have an answer. )
>
> The relevant functions are from 'tcrdb' in tokyotyrant; three which take
> 'uint64_t' timestamps in microseconds, and two which return them.
> Is there another way to do this manipulation? Or am I just being silly? (I'm
> pretty sure I can write a little C.)

I'm not familiar with alien, but I think you'd have to write C code to
create a uint64 userdata.

Google the list for lots of discussion.

But, do people need to do arithmetic on the timestamps? I.e., do they
really need to pass them around as numbers? Add them? Divide them?
Pass to math.sin()? Probably not. It's convenient to keep timestamps
as a numeric type in C, but not in Lua.

I'd suggest using a string to pass them around as the decimal
representation of usecs, that makes them easy to print, and easy to
set. You could even provide library functions:

 tokyotimestamp.diff(a, b)
 tokyotimestamp.cmp(a, b)
     .breakdown(a) -> return seconds and microseconds (easy to do by
truncating bottom 6 characters, and then returning tonumber() of the
seconds part and microseconds part?)

Converting to/from uint64 and a string is easy in C.

Cheers,
Sam