bool CopyOnWriteContext::notifyTupleDelete(TableTuple &tuple) { assert(m_iterator != NULL); if (tuple.isDirty() || m_finishedTableScan) { return true; } /** * Find out which block the address is contained in. Lower bound returns the first entry * in the index >= the address. Unless the address happens to be equal then the block * we are looking for is probably the previous entry. Then check if the address fits * in the previous entry. If it doesn't then the block is something new. */ TBPtr block = PersistentTable::findBlock(tuple.address(), m_blocks, getTable().getTableAllocationSize()); if (block.get() == NULL) { // tuple not in snapshot region, don't care about this tuple return true; } /** * Now check where this is relative to the COWIterator. */ CopyOnWriteIterator *iter = reinterpret_cast<CopyOnWriteIterator*>(m_iterator.get()); return !iter->needToDirtyTuple(block->address(), tuple.address()); }
void CopyOnWriteContext::markTupleDirty(TableTuple tuple, bool newTuple) { assert(m_iterator != NULL); if (newTuple) { m_inserts++; } else { m_updates++; } /** * If this an update or a delete of a tuple that is already dirty then no further action is * required. */ if (!newTuple && tuple.isDirty()) { return; } /** * If the table has been scanned already there is no need to continue marking tuples dirty * If the tuple is dirty then it has already been backed up. */ if (m_finishedTableScan) { tuple.setDirtyFalse(); return; } /** * Find out which block the address is contained in. */ TBPtr block = PersistentTable::findBlock(tuple.address(), m_blocks, getTable().getTableAllocationSize()); if (block.get() == NULL) { // tuple not in snapshot region, don't care about this tuple, no need to dirty it tuple.setDirtyFalse(); return; } /** * Now check where this is relative to the COWIterator. */ CopyOnWriteIterator *iter = reinterpret_cast<CopyOnWriteIterator*>(m_iterator.get()); if (iter->needToDirtyTuple(block->address(), tuple.address())) { tuple.setDirtyTrue(); /** * Don't back up a newly introduced tuple, just mark it as dirty. */ if (!newTuple) { m_backedUpTuples->insertTupleNonVirtualWithDeepCopy(tuple, &m_pool); } } else { tuple.setDirtyFalse(); return; } }
void CopyOnWriteContext::notifyBlockWasCompactedAway(TBPtr block) { assert(m_iterator != NULL); if (m_finishedTableScan) { // There was a compaction while we are iterating through the m_backedUpTuples // TempTable. Don't do anything because the passed in block is a PersistentTable // block return; } m_blocksCompacted++; CopyOnWriteIterator *iter = static_cast<CopyOnWriteIterator*>(m_iterator.get()); TBPtr nextBlock = iter->m_blockIterator.data(); TBPtr newNextBlock = iter->m_blockIterator.data(); iter->notifyBlockWasCompactedAway(block); }
bool CopyOnWriteContext::notifyTupleDelete(TableTuple &tuple) { assert(m_iterator != NULL); if (tuple.isDirty() || m_finishedTableScan) { return true; } // This is a 'loose' count of the number of deletes because COWIterator could be past this // point in the block. m_deletes++; /** * Now check where this is relative to the COWIterator. */ CopyOnWriteIterator *iter = reinterpret_cast<CopyOnWriteIterator*>(m_iterator.get()); return !iter->needToDirtyTuple(tuple.address()); }
void CopyOnWriteContext::markTupleDirty(TableTuple tuple, bool newTuple) { assert(m_iterator != NULL); /** * If this an update or a delete of a tuple that is already dirty then no further action is * required. */ if (!newTuple && tuple.isDirty()) { return; } /** * If the table has been scanned already there is no need to continue marking tuples dirty * If the tuple is dirty then it has already been backed up. */ if (m_finishedTableScan) { tuple.setDirtyFalse(); return; } /** * Now check where this is relative to the COWIterator. */ CopyOnWriteIterator *iter = reinterpret_cast<CopyOnWriteIterator*>(m_iterator.get()); if (iter->needToDirtyTuple(tuple.address())) { tuple.setDirtyTrue(); if (newTuple) { /** * Don't back up a newly introduced tuple, just mark it as dirty. */ m_inserts++; } else { m_updates++; m_backedUpTuples->insertTempTupleDeepCopy(tuple, &m_pool); } } else { tuple.setDirtyFalse(); return; } }
bool CopyOnWriteContext::canSafelyFreeTuple(TableTuple tuple) { assert(m_iterator != NULL); if (tuple.isDirty() || m_finishedTableScan) { return true; } /** * Find out which block the address is contained in. Lower bound returns the first entry * in the index >= the address. Unless the address happens to be equal then the block * we are looking for is probably the previous entry. Then check if the address fits * in the previous entry. If it doesn't then the block is something new. */ char *address = tuple.address(); TBMapI i = m_blocks.lower_bound(address); if (i == m_blocks.end() && m_blocks.empty()) { return true; } if (i == m_blocks.end()) { i--; if (i.key() + getTable().m_tableAllocationSize < address) { return true; } //OK it is in the very last block } else { if (i.key() != address) { i--; if (i.key() + getTable().m_tableAllocationSize < address) { return true; } //OK... this is in this particular block } } const char *blockStartAddress = i.key(); /** * Now check where this is relative to the COWIterator. */ CopyOnWriteIterator *iter = reinterpret_cast<CopyOnWriteIterator*>(m_iterator.get()); return !iter->needToDirtyTuple(blockStartAddress, address); }
void CopyOnWriteContext::markTupleDirty(TableTuple tuple, bool newTuple) { if (newTuple) { m_inserts++; } else { m_updates++; } /** * If this an update or a delete of a tuple that is already dirty then no further action is * required. */ if (!newTuple && tuple.isDirty()) { return; } /** * If the table has been scanned already there is no need to continue marking tuples dirty * If the tuple is dirty then it has already been backed up. */ if (m_finishedTableScan) { tuple.setDirtyFalse(); return; } /** * Find out which block the address is contained in. */ char *address = tuple.address(); TBMapI i = m_blocks.lower_bound(address); if (i == m_blocks.end() && m_blocks.empty()) { tuple.setDirtyFalse(); return; } if (i == m_blocks.end()) { i--; if (i.key() + m_table.m_tableAllocationSize < address) { tuple.setDirtyFalse(); return; } //OK it is in the very last block } else { if (i.key() != address) { i--; if (i.key() + m_table.m_tableAllocationSize < address) { tuple.setDirtyFalse(); return; } //OK... this is in this particular block } } const char *blockStartAddress = i.key(); /** * Now check where this is relative to the COWIterator. */ CopyOnWriteIterator *iter = reinterpret_cast<CopyOnWriteIterator*>(m_iterator.get()); if (iter->needToDirtyTuple(blockStartAddress, address)) { tuple.setDirtyTrue(); /** * Don't back up a newly introduced tuple, just mark it as dirty. */ if (!newTuple) { m_backedUpTuples->insertTupleNonVirtualWithDeepCopy(tuple, &m_pool); } } else { tuple.setDirtyFalse(); return; } }
void CopyOnWriteContext::markTupleDirty(TableTuple tuple, bool newTuple) { /** * If this an update or a delete of a tuple that is already dirty then no further action is * required. */ if (!newTuple && tuple.isDirty()) { return; } /** * If the table has been scanned already there is no need to continue marking tuples dirty * If the tuple is dirty then it has already been backed up. */ if (m_finishedTableScan) { tuple.setDirtyFalse(); return; } /** * Find out which block the address is contained in. */ char *address = tuple.address(); #ifdef MEMCHECK BlockPair compP; compP.pair = std::pair<char*, int>(address, 0); compP.tupleLength = tuple.tupleLength(); #else const BlockPair compP(address, 0); #endif BlockPairVectorI i = std::lower_bound(m_blocks.begin(), m_blocks.end(), compP, pairAddressToPairAddressComparator); if (i == m_blocks.end()) { tuple.setDirtyFalse(); return; } #ifdef MEMCHECK const char *blockStartAddress = (*i).pair.first; const int blockIndex = (*i).pair.second; const char *blockEndAddress = blockStartAddress + tuple.tupleLength(); #else const char *blockStartAddress = (*i).first; const int blockIndex = (*i).second; const char *blockEndAddress = blockStartAddress + TABLE_BLOCKSIZE; #endif if (address >= blockEndAddress || address < blockStartAddress) { /** * Tuple is in a block allocated after the start of COW */ tuple.setDirtyFalse(); return; } /** * Now check where this is relative to the COWIterator. */ CopyOnWriteIterator *iter = reinterpret_cast<CopyOnWriteIterator*>(m_iterator.get()); if (iter->needToDirtyTuple(blockIndex, address, newTuple)) { tuple.setDirtyTrue(); /** * Don't back up a newly introduced tuple, just mark it as dirty. */ if (!newTuple) { m_backedUpTuples->insertTupleNonVirtualWithDeepCopy(tuple, &m_pool); } } else { tuple.setDirtyFalse(); return; } }