use of org.neo4j.kernel.impl.store.UnderlyingStorageException in project neo4j by neo4j.
the class IdGeneratorImpl method initGenerator.
// initialize the id generator and performs a simple validation
private synchronized void initGenerator() {
try {
fileChannel = fs.open(file, "rw");
ByteBuffer buffer = readHeader();
markAsSticky(fileChannel, buffer);
fileChannel.position(HEADER_SIZE);
this.keeper = new FreeIdKeeper(fileChannel, grabSize, aggressiveReuse);
} catch (IOException e) {
throw new UnderlyingStorageException("Unable to init id generator " + file, e);
}
}
use of org.neo4j.kernel.impl.store.UnderlyingStorageException in project neo4j by neo4j.
the class IdGeneratorImpl method createGenerator.
/**
* Creates a new id generator.
*
* @param fileName The name of the id generator
* @param throwIfFileExists if {@code true} will cause an {@link UnderlyingStorageException} to be thrown if
* the file already exists. if {@code false} will truncate the file writing the header in it.
*/
public static void createGenerator(FileSystemAbstraction fs, File fileName, long highId, boolean throwIfFileExists) {
// sanity checks
if (fs == null) {
throw new IllegalArgumentException("Null filesystem");
}
if (fileName == null) {
throw new IllegalArgumentException("Null filename");
}
if (throwIfFileExists && fs.fileExists(fileName)) {
throw new IllegalStateException("Can't create IdGeneratorFile[" + fileName + "], file already exists");
}
try (StoreChannel channel = fs.create(fileName)) {
// write the header
channel.truncate(0);
ByteBuffer buffer = ByteBuffer.allocate(HEADER_SIZE);
buffer.put(CLEAN_GENERATOR).putLong(highId).flip();
channel.write(buffer);
channel.force(false);
} catch (IOException e) {
throw new UnderlyingStorageException("Unable to create id generator" + fileName, e);
}
}
use of org.neo4j.kernel.impl.store.UnderlyingStorageException in project neo4j by neo4j.
the class LabelsAcceptanceTest method beansAPIWithNoMoreLabelIds.
@SuppressWarnings("deprecation")
private GraphDatabaseService beansAPIWithNoMoreLabelIds() {
final EphemeralIdGenerator.Factory idFactory = new EphemeralIdGenerator.Factory() {
private IdTypeConfigurationProvider idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider();
@Override
public IdGenerator open(File fileName, int grabSize, IdType idType, long highId, long maxId) {
if (idType == IdType.LABEL_TOKEN) {
IdGenerator generator = generators.get(idType);
if (generator == null) {
IdTypeConfiguration idTypeConfiguration = idTypeConfigurationProvider.getIdTypeConfiguration(idType);
generator = new EphemeralIdGenerator(idType, idTypeConfiguration) {
@Override
public long nextId() {
// Same exception as the one thrown by IdGeneratorImpl
throw new UnderlyingStorageException("Id capacity exceeded");
}
};
generators.put(idType, generator);
}
return generator;
}
return super.open(fileName, grabSize, idType, Long.MAX_VALUE, Long.MAX_VALUE);
}
};
TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory() {
@Override
protected GraphDatabaseBuilder.DatabaseCreator createImpermanentDatabaseCreator(final File storeDir, final TestGraphDatabaseFactoryState state) {
return new GraphDatabaseBuilder.DatabaseCreator() {
@Override
public GraphDatabaseService newDatabase(Map<String, String> config) {
return newDatabase(Config.embeddedDefaults(config));
}
@Override
public GraphDatabaseService newDatabase(@Nonnull Config config) {
return new ImpermanentGraphDatabase(storeDir, config, GraphDatabaseDependencies.newDependencies(state.databaseDependencies())) {
@Override
protected void create(File storeDir, Config config, GraphDatabaseFacadeFactory.Dependencies dependencies) {
Function<PlatformModule, EditionModule> factory = (platformModule) -> new CommunityEditionModule(platformModule) {
@Override
protected IdGeneratorFactory createIdGeneratorFactory(FileSystemAbstraction fs, IdTypeConfigurationProvider idTypeConfigurationProvider) {
return idFactory;
}
};
new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, factory) {
@Override
protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
return new ImpermanentPlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade);
}
}.initFacade(storeDir, config, dependencies, this);
}
};
}
};
}
};
return dbFactory.newImpermanentDatabase();
}
use of org.neo4j.kernel.impl.store.UnderlyingStorageException in project neo4j by neo4j.
the class IndexUpdaterMap method close.
@Override
public void close() throws UnderlyingStorageException {
Set<Pair<NewIndexDescriptor, UnderlyingStorageException>> exceptions = null;
for (Map.Entry<LabelSchemaDescriptor, IndexUpdater> updaterEntry : updaterMap.entrySet()) {
IndexUpdater updater = updaterEntry.getValue();
try {
updater.close();
} catch (IOException | IndexEntryConflictException e) {
if (null == exceptions) {
exceptions = new HashSet<>();
}
exceptions.add(Pair.of(NewIndexDescriptorFactory.forSchema(updaterEntry.getKey()), new UnderlyingStorageException(e)));
}
}
clear();
if (null != exceptions) {
throw new MultipleUnderlyingStorageExceptions(exceptions);
}
}
use of org.neo4j.kernel.impl.store.UnderlyingStorageException in project neo4j by neo4j.
the class FreeIdKeeper method readIdBatch.
/*
* After this method returns, if there were any entries found, they are placed in the readFromDisk list and the
* readPosition is updated accordingly.
*/
private void readIdBatch() {
if (!canReadMoreIdBatches()) {
return;
}
try {
int howMuchToRead = (int) Math.min(threshold * ID_ENTRY_SIZE, maxReadPosition - readPosition);
assert howMuchToRead % ID_ENTRY_SIZE == 0 : "reads should happen in multiples of ID_ENTRY_SIZE, instead was " + howMuchToRead;
ByteBuffer readBuffer = ByteBuffer.allocate(howMuchToRead);
positionChannel(readPosition);
int bytesRead = channel.read(readBuffer);
readPosition += bytesRead;
assert channel.position() <= maxReadPosition;
readBuffer.flip();
assert (bytesRead % ID_ENTRY_SIZE) == 0;
int idsRead = bytesRead / ID_ENTRY_SIZE;
for (int i = 0; i < idsRead; i++) {
long id = readBuffer.getLong();
if (id != NO_RESULT) {
readFromDisk.add(id);
}
}
} catch (IOException e) {
throw new UnderlyingStorageException("Failed reading defragged id batch", e);
}
}
Aggregations