Sirikata
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
Sirikata::OH::SQLiteStorage Class Reference

#include <SQLiteStorage.hpp>

Inheritance diagram for Sirikata::OH::SQLiteStorage:
Collaboration diagram for Sirikata::OH::SQLiteStorage:

List of all members.

Classes

struct  BucketRenewTimeout
struct  StorageAction
struct  TransactionData

Public Member Functions

 SQLiteStorage (ObjectHostContext *ctx, const String &dbpath, const Duration &lease_duration)
 ~SQLiteStorage ()
virtual void start ()
 Service Interface.
virtual void stop ()
virtual void leaseBucket (const Bucket &bucket)
 Trigger a lease on a bucket.
virtual void releaseBucket (const Bucket &bucket)
 Release whatever lease or lock was acquired by the corresponding call to leaseBucket.
virtual void beginTransaction (const Bucket &bucket)
 Begin a transaction.
virtual void commitTransaction (const Bucket &bucket, const CommitCallback &cb=0, const String &timestamp="current")
 Completes a transaction and requests that it be written to Flushes all outstanding events (writes and removes) from pending queue.
virtual bool erase (const Bucket &bucket, const Key &key, const CommitCallback &cb=0, const String &timestamp="current")
virtual bool write (const Bucket &bucket, const Key &key, const String &value, const CommitCallback &cb=0, const String &timestamp="current")
 Queues writes to the item named by entryName:itemName.
virtual bool read (const Bucket &bucket, const Key &key, const CommitCallback &cb=0, const String &timestamp="current")
virtual bool compare (const Bucket &bucket, const Key &key, const String &value, const CommitCallback &cb=0, const String &timestamp="current")
 Add a comparison operation to the transaction.
virtual bool rangeRead (const Bucket &bucket, const Key &start, const Key &finish, const CommitCallback &cb=0, const String &timestamp="current")
virtual bool rangeErase (const Bucket &bucket, const Key &start, const Key &finish, const CommitCallback &cb=0, const String &timestamp="current")
virtual bool count (const Bucket &bucket, const Key &start, const Key &finish, const CountCallback &cb=0, const String &timestamp="current")

Private Types

typedef std::vector
< StorageAction
Transaction
typedef
std::tr1::unordered_map
< Bucket, Transaction
*, Bucket::Hasher
BucketTransactions
typedef
ThreadSafeQueueWithNotification
< TransactionData
TransactionQueue

Private Member Functions

void initDB ()
TransactiongetTransaction (const Bucket &bucket, bool *is_new=NULL)
void postProcessTransactions ()
void processTransactions ()
Result executeCommit (const Bucket &bucket, Transaction *trans, CommitCallback cb, ReadSet **read_set_out)
void executeCount (const String value_count, const Key &start, const Key &finish, CountCallback cb)
bool sqlBeginTransaction ()
bool sqlCommit ()
bool sqlRollback ()
String getLeaseString ()
void parseLeaseString (const String &ls, String *client_out, Time *expiration_out)
Result acquireLease (const Bucket &bucket)
void renewLease (const Bucket &bucket)
void releaseLease (const Bucket &bucket)
void processRenewals ()

Static Private Member Functions

static bool checkSQLiteError (SQLiteDBPtr db, int rc, const String &msg)

Private Attributes

ObjectHostContextmContext
BucketTransactions mTransactions
String mDBFilename
SQLiteDBPtr mDB
Network::IOServicemIOService
Network::IOWorkmWork
ThreadmThread
const String mSQLClientID
const Duration mLeaseDuration
TransactionQueue mTransactionQueue
uint32 mMaxCoalescedTransactions
const Duration mRetrySleepDuration
const int32 mNormalOpRetries
const int32 mLeaseOpRetries
std::queue< BucketRenewTimeoutmRenewTimes
Network::IOTimerPtr mRenewTimer

Member Typedef Documentation


Constructor & Destructor Documentation

Sirikata::OH::SQLiteStorage::SQLiteStorage ( ObjectHostContext ctx,
const String &  dbpath,
const Duration lease_duration 
)
Sirikata::OH::SQLiteStorage::~SQLiteStorage ( )

Member Function Documentation

Storage::Result Sirikata::OH::SQLiteStorage::acquireLease ( const Bucket bucket) [private]
void Sirikata::OH::SQLiteStorage::beginTransaction ( const Bucket bucket) [virtual]

Begin a transaction.

Implements Sirikata::OH::Storage.

References getTransaction().

bool Sirikata::OH::SQLiteStorage::checkSQLiteError ( SQLiteDBPtr  db,
int  rc,
const String &  msg 
) [static, private]
void Sirikata::OH::SQLiteStorage::commitTransaction ( const Bucket bucket,
const CommitCallback cb = 0,
const String &  timestamp = "current" 
) [virtual]

Completes a transaction and requests that it be written to Flushes all outstanding events (writes and removes) from pending queue.

Resets pending queue as well.

Implements Sirikata::OH::Storage.

References getTransaction(), mTransactionQueue, mTransactions, Sirikata::ThreadSafeQueueWithNotification< T >::push(), and Sirikata::OH::Storage::SUCCESS.

Referenced by compare(), erase(), rangeErase(), rangeRead(), read(), and write().

bool Sirikata::OH::SQLiteStorage::compare ( const Bucket bucket,
const Key key,
const String &  value,
const CommitCallback cb = 0,
const String &  timestamp = "current" 
) [virtual]

Add a comparison operation to the transaction.

The given key is read and compared to the value. If the comparison is false, it causes the entire transaction to fail.

Parameters:
{Key}key the key to compare to
{String}value What should be written into that item
{CommitCallback}cb optional commit callback which is invoked if this is a single operation transaction.
{String}timestamp the timestamp of the operation
Returns:
{bool} true if the read is queued, false otherwise. Does not indicated success of actual read operation.

Implements Sirikata::OH::Storage.

References commitTransaction(), Sirikata::OH::SQLiteStorage::StorageAction::Compare, getTransaction(), Sirikata::OH::SQLiteStorage::StorageAction::key, Sirikata::OH::SQLiteStorage::StorageAction::type, and Sirikata::OH::SQLiteStorage::StorageAction::value.

bool Sirikata::OH::SQLiteStorage::count ( const Bucket bucket,
const Key start,
const Key finish,
const CountCallback cb = 0,
const String &  timestamp = "current" 
) [virtual]
Parameters:
{Key}from the start key of range of keys to count
{Key}finish the end key of range of keys to count
{CommitCallback}cb optional commit callback which is invoked if this is a single operation transaction.
{String}timestamp the timestamp of the operation
Returns:
{bool} true if operation is successful, false otherwise

Implements Sirikata::OH::Storage.

References executeCount(), mIOService, Sirikata::Network::IOService::post(), Sirikata::UUID::rawHexData(), and TABLE_NAME.

Referenced by executeCount().

bool Sirikata::OH::SQLiteStorage::erase ( const Bucket bucket,
const Key key,
const CommitCallback cb = 0,
const String &  timestamp = "current" 
) [virtual]
Parameters:
{Key}key the key to erase
{CommitCallback}cb optional commit callback which is invoked if this is a single operation transaction.
{String}timestamp the timestamp of the operation
Returns:
{bool} true if the erase is queued, false otherwise. Does not indicated success of actual erase operation.

Queues the item to be removed from the backend. Does not actually delete until the flush operation is called.

Erasing a non-existant key does not cause an error -- it's just treated as a noop. If you care that a key is actually erase, use a compare + delete combination.

Implements Sirikata::OH::Storage.

References commitTransaction(), Sirikata::OH::SQLiteStorage::StorageAction::Erase, getTransaction(), Sirikata::OH::SQLiteStorage::StorageAction::key, and Sirikata::OH::SQLiteStorage::StorageAction::type.

Storage::Result Sirikata::OH::SQLiteStorage::executeCommit ( const Bucket bucket,
Transaction trans,
CommitCallback  cb,
ReadSet **  read_set_out 
) [private]
void Sirikata::OH::SQLiteStorage::executeCount ( const String  value_count,
const Key start,
const Key finish,
CountCallback  cb 
) [private]
String Sirikata::OH::SQLiteStorage::getLeaseString ( ) [private]
SQLiteStorage::Transaction * Sirikata::OH::SQLiteStorage::getTransaction ( const Bucket bucket,
bool *  is_new = NULL 
) [private]
void Sirikata::OH::SQLiteStorage::initDB ( ) [private]
void Sirikata::OH::SQLiteStorage::leaseBucket ( const Bucket bucket) [virtual]

Trigger a lease on a bucket.

This is just a signal to the storage layer that it should try to make sure it can commit transactions for the bucket. Depending on the implementation and options, this could mean anything from doing nothing (single process, local operation) to a full lease or lock (distributed storage).

Implements Sirikata::OH::Storage.

void Sirikata::OH::SQLiteStorage::parseLeaseString ( const String &  ls,
String *  client_out,
Time expiration_out 
) [private]
void Sirikata::OH::SQLiteStorage::postProcessTransactions ( ) [private]
void Sirikata::OH::SQLiteStorage::processRenewals ( ) [private]
void Sirikata::OH::SQLiteStorage::processTransactions ( ) [private]
bool Sirikata::OH::SQLiteStorage::rangeErase ( const Bucket bucket,
const Key start,
const Key finish,
const CommitCallback cb = 0,
const String &  timestamp = "current" 
) [virtual]
Parameters:
{Key}from the start key of range of keys to erase
{Key}finish the end key of range of keys to erase
{CommitCallback}cb optional commit callback which is invoked if this is a single operation transaction.
{String}timestamp the timestamp of the operation
Returns:
{bool} true if the read is queued, false otherwise. Does not indicated success of actual erase operation.

Implements Sirikata::OH::Storage.

References commitTransaction(), Sirikata::OH::SQLiteStorage::StorageAction::EraseRange, getTransaction(), Sirikata::OH::SQLiteStorage::StorageAction::key, Sirikata::OH::SQLiteStorage::StorageAction::keyEnd, start(), and Sirikata::OH::SQLiteStorage::StorageAction::type.

bool Sirikata::OH::SQLiteStorage::rangeRead ( const Bucket bucket,
const Key start,
const Key finish,
const CommitCallback cb = 0,
const String &  timestamp = "current" 
) [virtual]
Parameters:
{Key}from the start key of range of keys to read
{Key}finish the end key of range of keys to read
{CommitCallback}cb optional commit callback which is invoked if this is a single operation transaction.
{String}timestamp the timestamp of the operation
Returns:
{bool} true if the read is queued, false otherwise. Does not indicated success of actual read operation.

Implements Sirikata::OH::Storage.

References commitTransaction(), getTransaction(), Sirikata::OH::SQLiteStorage::StorageAction::key, Sirikata::OH::SQLiteStorage::StorageAction::keyEnd, Sirikata::OH::SQLiteStorage::StorageAction::ReadRange, start(), and Sirikata::OH::SQLiteStorage::StorageAction::type.

bool Sirikata::OH::SQLiteStorage::read ( const Bucket bucket,
const Key key,
const CommitCallback cb = 0,
const String &  timestamp = "current" 
) [virtual]
Parameters:
{Key}key the key to read
{CommitCallback}cb optional commit callback which is invoked if this is a single operation transaction.
{String}timestamp the timestamp of the operation
Returns:
{bool} true if the read is queued, false otherwise. Does not indicated success of actual read operation.

Implements Sirikata::OH::Storage.

References commitTransaction(), getTransaction(), Sirikata::OH::SQLiteStorage::StorageAction::key, Sirikata::OH::SQLiteStorage::StorageAction::Read, and Sirikata::OH::SQLiteStorage::StorageAction::type.

void Sirikata::OH::SQLiteStorage::releaseBucket ( const Bucket bucket) [virtual]

Release whatever lease or lock was acquired by the corresponding call to leaseBucket.

Implements Sirikata::OH::Storage.

References mIOService, Sirikata::Network::IOService::post(), and releaseLease().

void Sirikata::OH::SQLiteStorage::releaseLease ( const Bucket bucket) [private]
void Sirikata::OH::SQLiteStorage::renewLease ( const Bucket bucket) [private]
bool Sirikata::OH::SQLiteStorage::sqlBeginTransaction ( ) [private]
bool Sirikata::OH::SQLiteStorage::sqlCommit ( ) [private]
bool Sirikata::OH::SQLiteStorage::sqlRollback ( ) [private]
void Sirikata::OH::SQLiteStorage::start ( ) [virtual]
void Sirikata::OH::SQLiteStorage::stop ( ) [virtual]
bool Sirikata::OH::SQLiteStorage::write ( const Bucket bucket,
const Key key,
const String &  value,
const CommitCallback cb = 0,
const String &  timestamp = "current" 
) [virtual]

Queues writes to the item named by entryName:itemName.

Writes will not be committed until flush command. Note, if issue this command multiple times with the same entryName:itemName, will only process the last when calling flush.

Parameters:
{Key}key the key to erase
{String}value What should be written into that item
{CommitCallback}cb optional commit callback which is invoked if this is a single operation transaction.
{String}timestamp the timestamp of the operation
Returns:
{bool} true if the write is queued, false otherwise. Does not indicated success of actual write operation.

Implements Sirikata::OH::Storage.

References commitTransaction(), getTransaction(), Sirikata::OH::SQLiteStorage::StorageAction::key, Sirikata::OH::SQLiteStorage::StorageAction::type, Sirikata::OH::SQLiteStorage::StorageAction::value, and Sirikata::OH::SQLiteStorage::StorageAction::Write.


Member Data Documentation

Referenced by initDB().

Referenced by processTransactions().

Referenced by executeCommit().

Referenced by start(), and stop().

Referenced by start(), and stop().


The documentation for this class was generated from the following files: