On 02/26/2013 02:57 PM, Michael Davidsaver wrote:
For some time now I've had the idea that it would be useful to have
API for executing a list of get/put DB operations. What would make
this most useful, and most difficult to implement, would be an option
to make such batch operations atomic (wrt. record locking). I've done
some investigations into how this might be implemented, and I think I
have a clear strategy. However, there are two questions I need to get
answered before I can proceed.
1) Can the three functions from dbLock.h mentioned below be removed
2) Is the proposed API for batch operations acceptable?
As I have not had any negative answers I've created a working demo of
this new API using the existing locking API. The DBOP_ATOMIC option is
implemented using dbLockSetRecordLock(), so it really is
uninterpretable, but this comes at the cost of serializing all operations.
The interesting files are
testBatch.c is a unit-test which demonstrates two batched operations.
The first is a get to one record, then a put to another. The second is
a compare and swap operation on a single field.
Note that testBatch is meant to be run from the top level of the source
tree in order to find needed .db and .dbd files.
tar -xzf dbbatch-pre1.tar.gz
The following is extracted from dbAccessBatch.h
/** @brief Batched Field Operations
* dbOpFields() executes a list of operations (DBOp structures).
* Execution stop on the first error. DBOp::status indicates
* completion status of each operation.
* The return value of dbOpFields() indicates a program logic
* error (invalid inputs). When an error is returned, the first
* DBOp with a non-zero status was the cause.
* Supported operations:
* - DBOpGet - Read the current field value into DBOp::userbuf
* - DBOpPut* - Write DBOp::userbuf into the field. Plain
* DBOpPut will process the record if the field
* has the PP attribute. DBOpPutNPP will never
* process, and DBOpPutPP will always process.
* - DBOpProc - Same as DBOpPutPP except the field is not modified.
* - DBOpEqual- Succeeds if the DBOp::userbuf is equal to the
* current field value. Only works for scalars.
* Modifier flags
* DBOP_FAST - Execute operations as quickly as possible.
* Locking is done for individual operations.
* DBOP_ATOMIC - Lock all effected record before first
* operation. No concurrent operation can intrude.
* May be quite slow when large numbers of records
* are involved.
- New API for batched dbGet/dbPut Michael Davidsaver
- Navigate by Date:
gethostbyname and getaddrinfo - multiple DNS entries for a hostname matthew.pearson
PMAC Gaudiello, Phillip
- Navigate by Thread:
New API for batched dbGet/dbPut Michael Davidsaver
Proposal to add site-specific TOP_RULES Benjamin Franksen