00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef Fennel_BTreeWriter_Included
00025 #define Fennel_BTreeWriter_Included
00026
00027 #include "fennel/btree/BTreeReader.h"
00028 #include "fennel/txn/LogicalTxnParticipant.h"
00029 #include "fennel/common/FemEnums.h"
00030
00031 #include <boost/scoped_array.hpp>
00032
00033 FENNEL_BEGIN_NAMESPACE
00034
00039 class FENNEL_BTREE_EXPORT BTreeWriter
00040 : public BTreeReader, public LogicalTxnParticipant
00041 {
00045 static const LogicalActionType ACTION_INSERT = 1;
00046
00050 static const LogicalActionType ACTION_DELETE = 2;
00051
00055 SegmentAccessor scratchAccessor;
00056
00060 BTreePageLock scratchPageLock;
00061
00066 std::vector<PageId> pageStack;
00067
00072 boost::scoped_array<FixedBuffer> splitTupleBuffer;
00073
00077 boost::scoped_array<FixedBuffer> leafTupleBuffer;
00078
00082 bool monotonic;
00083
00084 inline void optimizeRootLockMode();
00085
00095 void compactNode(BTreePageLock &targetPageLock);
00096
00107 void splitCurrentNode(
00108 PConstBuffer pTupleBuffer,
00109 uint cbTuple,
00110 uint iNewTuple);
00111
00123 void grow(
00124 BTreeNode const &rightNode, PageId rightPageId);
00125
00140 uint lockParentPage(uint height, bool rightMostNode);
00141
00157 bool attemptInsertWithoutSplit(
00158 BTreePageLock &targetPageLock,
00159 PConstBuffer pTupleBuffer,uint cbTuple,uint iNewTuple);
00160
00166 void insertLogged(ByteInputStream &logStream);
00167
00173 void deleteLogged(ByteInputStream &logStream);
00174
00182 bool positionSearchKey(BTreeNodeAccessor &nodeAccessor);
00183
00197 bool checkMonotonicity(
00198 BTreeNodeAccessor &nodeAccessor, PConstBuffer pTupleBuffer);
00199
00200 public:
00210 explicit BTreeWriter(
00211 BTreeDescriptor const &descriptor,
00212 SegmentAccessor const &scratchAccessor,
00213 bool monotonic = false);
00214
00215 virtual ~BTreeWriter();
00216
00227 void insertTupleData(
00228 TupleData const &tupleData,
00229 Distinctness distinctness);
00230
00243 uint insertTupleFromBuffer(
00244 PConstBuffer pTupleBuffer,Distinctness distinctness);
00245
00251 void deleteCurrent();
00252
00266 bool updateCurrent(TupleData const &tupleData);
00267
00271 void releaseScratchBuffers();
00272
00273
00274 virtual LogicalTxnClassId getParticipantClassId() const;
00275 virtual void describeParticipant(
00276 ByteOutputStream &logStream);
00277 virtual void undoLogicalAction(
00278 LogicalActionType actionType,
00279 ByteInputStream &logStream);
00280 virtual void redoLogicalAction(
00281 LogicalActionType actionType,
00282 ByteInputStream &logStream);
00283 };
00284
00285 FENNEL_END_NAMESPACE
00286
00287 #endif
00288
00289