use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.
the class CommonAbstractStore method rebuildIdGenerator.
/**
* Should rebuild the id generator from scratch.
* <p>
* Note: This method may be called both while the store has the store file mapped in the
* page cache, and while the store file is not mapped. Implementers must therefore
* map their own temporary PagedFile for the store file, and do their file IO through that,
* if they need to access the data in the store file.
*/
final void rebuildIdGenerator() {
int blockSize = getRecordSize();
if (blockSize <= 0) {
throw new InvalidRecordException("Illegal blockSize: " + blockSize);
}
log.info("Rebuilding id generator for[" + getStorageFileName() + "] ...");
closeIdGenerator();
createIdGenerator(getIdFileName());
openIdGenerator();
long defraggedCount = 0;
boolean fastRebuild = isOnlyFastIdGeneratorRebuildEnabled(configuration);
try {
long foundHighId = scanForHighId();
setHighId(foundHighId);
if (!fastRebuild) {
try (PageCursor cursor = storeFile.io(0, PF_SHARED_WRITE_LOCK | PF_READ_AHEAD)) {
defraggedCount = rebuildIdGeneratorSlow(cursor, getRecordsPerPage(), blockSize, foundHighId);
}
}
} catch (IOException e) {
throw new UnderlyingStorageException("Unable to rebuild id generator " + getStorageFileName(), e);
}
log.info("[" + getStorageFileName() + "] high id=" + getHighId() + " (defragged=" + defraggedCount + ")");
log.info(getStorageFileName() + " rebuild id generator, highId=" + getHighId() + " defragged count=" + defraggedCount);
if (!fastRebuild) {
closeIdGenerator();
openIdGenerator();
}
}
use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.
the class MetaDataStore method setRecord.
/**
* Writes a record in a neostore file.
* This method only works for neostore files of the current version.
*
* @param pageCache {@link PageCache} the {@code neostore} file lives in.
* @param neoStore {@link File} pointing to the neostore.
* @param position record {@link Position}.
* @param value value to write in that record.
* @return the previous value before writing.
* @throws IOException if any I/O related error occurs.
*/
public static long setRecord(PageCache pageCache, File neoStore, Position position, long value) throws IOException {
long previousValue = FIELD_NOT_INITIALIZED;
int pageSize = getPageSize(pageCache);
try (PagedFile pagedFile = pageCache.map(neoStore, pageSize)) {
int offset = offset(position);
try (PageCursor cursor = pagedFile.io(0, PagedFile.PF_SHARED_WRITE_LOCK)) {
if (cursor.next()) {
// We're overwriting a record, get the previous value
cursor.setOffset(offset);
byte inUse = cursor.getByte();
long record = cursor.getLong();
if (inUse == Record.IN_USE.byteValue()) {
previousValue = record;
}
// Write the value
cursor.setOffset(offset);
cursor.putByte(Record.IN_USE.byteValue());
cursor.putLong(value);
if (cursor.checkAndClearBoundsFlag()) {
MetaDataRecord neoStoreRecord = new MetaDataRecord();
neoStoreRecord.setId(position.id);
throw new UnderlyingStorageException(buildOutOfBoundsExceptionMessage(neoStoreRecord, 0, offset, RECORD_SIZE, pageSize, neoStore.getAbsolutePath()));
}
}
}
}
return previousValue;
}
use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.
the class MetaDataStore method setUpgradeTransaction.
public void setUpgradeTransaction(long id, long checksum, long timestamp) {
long pageId = pageIdForRecord(Position.UPGRADE_TRANSACTION_ID.id);
assert pageId == pageIdForRecord(Position.UPGRADE_TRANSACTION_CHECKSUM.id);
synchronized (upgradeTransactionLock) {
try (PageCursor cursor = storeFile.io(pageId, PF_SHARED_WRITE_LOCK)) {
if (!cursor.next()) {
throw new UnderlyingStorageException("Could not access MetaDataStore page " + pageId);
}
setRecord(cursor, Position.UPGRADE_TRANSACTION_ID, id);
setRecord(cursor, Position.UPGRADE_TRANSACTION_CHECKSUM, checksum);
setRecord(cursor, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, timestamp);
upgradeTxIdField = id;
upgradeTxChecksumField = checksum;
upgradeCommitTimestampField = timestamp;
upgradeTransaction = new TransactionId(id, checksum, timestamp);
} catch (IOException e) {
throw new UnderlyingStorageException(e);
}
}
}
use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.
the class ConfigurableStandalonePageCacheFactoryTest method mustAutomaticallyStartEvictionThread.
@Test(timeout = 10000)
public void mustAutomaticallyStartEvictionThread() throws IOException {
try (FileSystemAbstraction fs = new DelegateFileSystemAbstraction(Jimfs.newFileSystem(jimConfig()))) {
File file = new File("/a").getCanonicalFile();
fs.create(file).close();
try (PageCache cache = ConfigurableStandalonePageCacheFactory.createPageCache(fs);
PagedFile pf = cache.map(file, 4096);
PageCursor cursor = pf.io(0, PagedFile.PF_SHARED_WRITE_LOCK)) {
// If the eviction thread has not been started, then this test will block forever.
for (int i = 0; i < 10_000; i++) {
assertTrue(cursor.next());
cursor.putInt(42);
}
}
}
}
use of org.neo4j.io.pagecache.PageCursor in project neo4j by neo4j.
the class CompositePageCursor method putByte.
@Override
public void putByte(byte value) {
PageCursor cursor = cursor(Byte.BYTES);
cursor.putByte(value);
offset++;
}
Aggregations