BTreeWriter.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/btree/BTreeWriter.h#20 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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     // implement LogicalTxnParticipant
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 // End BTreeWriter.h

Generated on Mon Jun 22 04:00:13 2009 for Fennel by  doxygen 1.5.1