1
0
Fork 0

fix some compaction issues

This commit is contained in:
Jan Steemann 2016-01-08 14:52:42 +01:00
parent 67147482ce
commit d0f730a614
3 changed files with 59 additions and 11 deletions

View File

@ -633,6 +633,8 @@ TRI_shape_t const* VocShaper::findShape(TRI_shape_t* shape, bool create) {
char const* m = static_cast<char const*>(slotInfo.mem) +
sizeof(triagens::wal::shape_marker_t);
TRI_ASSERT(m != nullptr);
TRI_shape_t const* result = reinterpret_cast<TRI_shape_t const*>(m);
{

View File

@ -40,7 +40,6 @@
#include "VocBase/vocbase.h"
#include "VocBase/VocShaper.h"
static char const* ReasonNoDatafiles =
"skipped compaction because collection has no datafiles";
static char const* ReasonCompactionBlocked =
@ -400,7 +399,12 @@ static void RenameDatafileCallback(TRI_datafile_t* datafile, void* data) {
document, compactor->_fid, false);
if (dfi != nullptr) {
*dfi = context->_dfi;
// use original statistics as a base
dfi->_numberDead -= context->_dfi._numberDead;
dfi->_sizeDead -= context->_dfi._sizeDead;
dfi->_numberDeletion = context->_dfi._numberDeletion;
// note: the compactor does not change (num|size)Alive|Shapes|Attributes|Transactions
} else {
LOG_ERROR("logic error: could not find compactor file information");
}
@ -441,6 +445,7 @@ static bool Compactifier(TRI_df_marker_t const* marker, void* data,
compaction_context_t* context = static_cast<compaction_context_t*>(data);
TRI_document_collection_t* document = context->_document;
TRI_voc_fid_t const targetFid = context->_compactor->_fid;
// new or updated document
if (marker->_type == TRI_DOC_MARKER_KEY_DOCUMENT ||
@ -457,15 +462,21 @@ static bool Compactifier(TRI_df_marker_t const* marker, void* data,
bool deleted = (found == nullptr || found->_rid > d->_rid);
if (deleted) {
// found a dead document
context->_dfi._numberDead += 1;
context->_dfi._sizeDead += AlignedSize(marker);
LOG_TRACE("found a stale document: %s", key);
return true;
}
// we found an index entry with a revision id <= the marker revision
auto oldPtr = found->getDataPtr();
if (!TRI_IsWalDataMarkerDatafile(oldPtr) &&
auto const isWalDataMarker = TRI_IsWalDataMarkerDatafile(oldPtr);
if (!isWalDataMarker &&
oldPtr != static_cast<void const*>(marker)) {
// the index points to a datafile marker, but not to THIS marker
context->_dfi._numberDead += 1;
context->_dfi._sizeDead += AlignedSize(marker);
return true;
}
@ -487,10 +498,15 @@ static bool Compactifier(TRI_df_marker_t const* marker, void* data,
// let marker point to the new position
found2->setDataPtr(result);
// update fid in case it changes
if (!isWalDataMarker && found2->_fid != targetFid) {
found2->_fid = targetFid;
}
// update datafile info
// keep track of alive stats
context->_dfi._numberAlive += 1;
context->_dfi._sizeAlive += AlignedSize(marker);
}
// deletions
@ -960,6 +976,38 @@ static void CompactifyDatafiles(TRI_document_collection_t* document,
}
}
}
if (n > 1) {
// this is a merge of multiple datafiles...
// now fuse the statistics of datafile 1..n into the 0th datafile's statistics
TRI_WRITE_LOCK_DATAFILES_DOC_COLLECTION(document);
TRI_doc_datafile_info_t* dst = TRI_FindDatafileInfoDocumentCollection(document, compactor->_fid, false);
if (dst != nullptr) {
for (size_t k = 1; k < n; ++k) {
auto compaction = static_cast<compaction_info_t const*>(TRI_AtVector(compactions, k));
TRI_doc_datafile_info_t* src = TRI_FindDatafileInfoDocumentCollection(document, compaction->_datafile->_fid, false);
if (src != nullptr) {
dst->_numberAlive += src->_numberAlive;
dst->_numberDead += src->_numberDead;
dst->_numberDeletion += src->_numberDeletion;
dst->_numberShapes += src->_numberShapes;
dst->_numberAttributes += src->_numberAttributes;
dst->_numberTransactions += src->_numberTransactions;
dst->_sizeAlive += src->_sizeAlive;
dst->_sizeDead += src->_sizeDead;
dst->_sizeShapes += src->_sizeShapes;
dst->_sizeAttributes += src->_sizeAttributes;
dst->_sizeTransactions += src->_sizeTransactions;
}
}
}
TRI_WRITE_UNLOCK_DATAFILES_DOC_COLLECTION(document);
}
for (i = 0; i < n; ++i) {
compaction_info_t* compaction =

View File

@ -1906,14 +1906,12 @@ bool TRI_CloseDatafile(TRI_datafile_t* datafile) {
return false;
}
else {
datafile->close(datafile);
datafile->_data = 0;
datafile->_next = 0;
datafile->_fd = -1;
datafile->close(datafile);
datafile->_data = nullptr;
datafile->_next = nullptr;
datafile->_fd = -1;
return true;
}
return true;
} else if (datafile->_state == TRI_DF_STATE_CLOSED) {
LOG_WARNING("closing an already closed datafile '%s'",
datafile->getName(datafile));