@@ -210,6 +210,23 @@ struct TruncateTimeTracker : public TimeTracker {
210
210
}
211
211
};
212
212
213
+ void reportPrimaryIndexInconsistency (
214
+ arangodb::Result const & res,
215
+ arangodb::velocypack::StringRef const & key,
216
+ arangodb::LocalDocumentId const & rev,
217
+ arangodb::LogicalCollection const & collection) {
218
+
219
+ if (res.is (TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND)) {
220
+ // Scandal! A primary index entry is pointing to nowhere! Let's report
221
+ // this to the authorities immediately:
222
+ LOG_TOPIC (" 42536" , ERR, arangodb::Logger::ENGINES)
223
+ << " Found primary index entry for which there is no actual "
224
+ " document: collection=" << collection.name () << " , _key="
225
+ << key << " , _rev=" << rev.id ();
226
+ TRI_ASSERT (false );
227
+ }
228
+ }
229
+
213
230
} // namespace
214
231
215
232
namespace arangodb {
@@ -949,11 +966,12 @@ Result RocksDBCollection::read(transaction::Methods* trx,
949
966
950
967
rocksdb::PinnableSlice ps;
951
968
Result res;
969
+ LocalDocumentId documentId;
952
970
do {
953
- LocalDocumentId const documentId = primaryIndex ()->lookupKey (trx, key, readOwnWrites);
971
+ documentId = primaryIndex ()->lookupKey (trx, key, readOwnWrites);
954
972
if (!documentId.isSet ()) {
955
973
res.reset (TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND);
956
- break ;
974
+ return res ;
957
975
} // else found
958
976
959
977
TRI_IF_FAILURE (" RocksDBCollection::read-delay" ) {
@@ -966,6 +984,7 @@ Result RocksDBCollection::read(transaction::Methods* trx,
966
984
}
967
985
} while (res.is (TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND) &&
968
986
RocksDBTransactionState::toState (trx)->ensureSnapshot ());
987
+ ::reportPrimaryIndexInconsistency (res, key, documentId, _logicalCollection);
969
988
return res;
970
989
}
971
990
@@ -1219,6 +1238,7 @@ Result RocksDBCollection::replace(transaction::Methods* trx,
1219
1238
res = lookupDocumentVPack (trx, oldDocumentId, previousPS,
1220
1239
/* readCache*/ true , /* fillCache*/ false , ReadOwnWrites::yes);
1221
1240
if (res.fail ()) {
1241
+ ::reportPrimaryIndexInconsistency (res, keyStr, oldDocumentId, _logicalCollection);
1222
1242
return res;
1223
1243
}
1224
1244
@@ -1334,7 +1354,9 @@ Result RocksDBCollection::remove(transaction::Methods& trx, velocypack::Slice sl
1334
1354
expectedId = RevisionId::fromSlice (slice);
1335
1355
}
1336
1356
1337
- return remove (trx, documentId, expectedId, previousMdr, options);
1357
+ Result res = remove (trx, documentId, expectedId, previousMdr, options);
1358
+ ::reportPrimaryIndexInconsistency (res, keyStr, documentId, _logicalCollection);
1359
+ return res;
1338
1360
}
1339
1361
1340
1362
Result RocksDBCollection::remove (transaction::Methods& trx, LocalDocumentId documentId,
0 commit comments