Skip to content
mtrencseni edited this page Aug 22, 2011 · 1 revision

Advanced Python scripts

By default, ScalienDB batches writes on the client-side and sends them off automatically to the server when the batch size reaches a certain limit. Reads go through this proxy so the batching is transparent to the user.

However, for example at the end of a web request we sometimes want to make sure the commands have been sent off:

table.set(...)
table.set(...)
client.submit() # send off writes to server now!

We can also decide to discard all batched commands so far:

client.rollback()

To control the batch limit in bytes, use:

client.set_batch_limit(5*1000*1000) # set to 5MB

You can also set the batch mode. There are three batch modes, the default described above (scaliendb.SDBP_BATCH_DEFAULT) and scaliendb.SDBP_BATCH_NOAUTOSUBMIT and scaliendb.SDBP_BATCH_SINGLE.

To set these:

client.set_batch_mode(scaliendb.SDBP_BATCH_DEFAULT) # this is the default

No auto submit means that when the batch limit is reached, instead of sending off the writes to the server the client library raises an exception. Single means that each command is sent off one-by-one, bypassing the batch mechanism (this will be slow!).

Sometimes you want to make sure that submit() is called at the end of a block:

with client.begin():
    for i in xrange(1000):
        table.set(i, i)
# client.submit() has been called automatically

You can change your mind though:

with client.begin():
    for i in xrange(1000):
        table.set(i, i)
        if 500 == i:
            client.rollback() # --------------------------------------------
            break
# client.submit() is still called, but all writes have been discarded here ^

Happy hacking!