boolean verbose)
throws DatabaseException {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setReadOnly(true);
Database db = env.openDatabase
(null, DbType.VLSN_MAP.getInternalName(), dbConfig);
Cursor cursor = null;
try {
if (verbose) {
System.out.println("Verifying VLSN index");
}
cursor = db.openCursor(null, CursorConfig.READ_COMMITTED);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
/*
* The first item in the database is the VLSNRange. All subsequent
* items are VLSNBuckets.
*/
int count = 0;
VLSNRange range = null;
VLSNBucket lastBucket = null;
Long lastKey = null;
VLSN firstVLSNSeen = VLSN.NULL_VLSN;
VLSN lastVLSNSeen = VLSN.NULL_VLSN;
while (cursor.getNext(key, data, null) ==
OperationStatus.SUCCESS) {
Long keyValue = LongBinding.entryToLong(key);
if (count == 0) {
if (keyValue != VLSNRange.RANGE_KEY) {
out.println("Wrong key value for range! " + range);
}
range = VLSNRange.readFromDatabase(data);
if (verbose) {
out.println("range=>" + range);
}
} else {
VLSNBucket bucket = VLSNBucket.readFromDatabase(data);
if (verbose) {
out.print("key=> " + keyValue);
out.println(" bucket=>" + bucket);
}
if (lastBucket != null) {
if (lastBucket.getLast().compareTo(bucket.getFirst())
>= 0) {
out.println("Buckets out of order.");
out.println("Last = " + lastKey + "/" +
lastBucket);
out.println("Current = " + keyValue + "/" +
bucket);
}
}
lastBucket = bucket;
lastKey = keyValue;
if ((firstVLSNSeen != null) && firstVLSNSeen.isNull()) {
firstVLSNSeen = bucket.getFirst();
}
lastVLSNSeen = bucket.getLast();
}
count++;
}
if (count == 0) {
out.println("VLSNIndex not on disk");
return;
}
if (firstVLSNSeen.compareTo(range.getFirst()) != 0) {
out.println("First VLSN in bucket = " + firstVLSNSeen +
" and doesn't match range " + range.getFirst());
}
if (lastVLSNSeen.compareTo(range.getLast()) != 0) {
out.println("Last VLSN in bucket = " + lastVLSNSeen +
" and doesn't match range " + range.getLast());
}
} finally {
if (cursor != null) {
cursor.close();
}
db.close();
}
}