protected void checkForClose() { if (closed) throw new OStorageException("WAL has been closed"); } }
@ConsoleCommand(splitInWords = false, description = "Execute a GREMLIN script") public void gremlin( @ConsoleParameter(name = "script-text", description = "The script text to execute") final String iScriptText) { checkForDatabase(); if (iScriptText == null || iScriptText.length() == 0) return; resetResultSet(); long start = System.currentTimeMillis(); try { final Object result = currentDatabase.command(new OCommandGremlin(iScriptText)).execute(); float elapsed = System.currentTimeMillis() - start; out.println("\n" + result); out.printf("\nScript executed in %f ms.", elapsed); } catch (OStorageException e) { final Throwable cause = e.getCause(); if (cause instanceof OCommandExecutorNotFoundException) out.printf("\nError: the GREMLIN command executor is not installed, check your configuration"); } }
if (e.getCause() instanceof OConcurrentModificationException) { reloadSequence(); } else {
private OStorageException error(String message) { return new OStorageException(message); }
/** * Checks if the storage is open. If it's closed an exception is raised. */ @SuppressWarnings("WeakerAccess") protected final void checkOpenness() { if (status != STATUS.OPEN) { throw new OStorageException("Storage " + name + " is not opened."); } }
private MemoryFile getFile(final int fileId) { final MemoryFile memoryFile = files.get(fileId); if (memoryFile == null) { throw new OStorageException("File with id " + fileId + " does not exist"); } return memoryFile; }
private void waitTillWriteWillBeFinished() { final Future<?> wf = writeFuture; if (wf != null) { try { wf.get(); } catch (final InterruptedException e) { throw OException.wrapException(new OStorageException("WAL write for storage " + storageName + " was interrupted"), e); } catch (final ExecutionException e) { throw OException.wrapException(new OStorageException("Error during WAL write for storage " + storageName), e); } } }
@Override public final long loadFile(final String fileName) { metadataLock.lock(); try { final Integer fileId = fileNameIdMap.get(fileName); if (fileId == null) { throw new OStorageException("File " + fileName + " does not exist."); } return composeFileId(id, fileId); } finally { metadataLock.unlock(); } }
@Override protected File createWalTempDirectory() { final File walDirectory = new File(getStoragePath().toFile(), "walIncrementalBackupRestoreDirectory"); if (walDirectory.exists()) { OFileUtils.deleteRecursively(walDirectory); } if (!walDirectory.mkdirs()) throw new OStorageException("Can not create temporary directory to store files created during incremental backup"); return walDirectory; }
private OLogSequenceNumber restoreFromCheckPoint(final OAbstractCheckPointStartRecord checkPointRecord) throws IOException { if (checkPointRecord instanceof OFuzzyCheckpointStartRecord) { return restoreFromFuzzyCheckPoint((OFuzzyCheckpointStartRecord) checkPointRecord); } if (checkPointRecord instanceof OFullCheckpointStartRecord) { return restoreFromFullCheckPoint((OFullCheckpointStartRecord) checkPointRecord); } throw new OStorageException("Unknown checkpoint record type " + checkPointRecord.getClass().getName()); }
public long filledUpTo(long fileId) { fileId = checkFileIdCompatibility(fileId, storageId); if (deletedFiles.contains(fileId)) { throw new OStorageException("File with id " + fileId + " is deleted."); } final FileChanges changesContainer = fileChanges.get(fileId); return internalFilledUpTo(fileId, changesContainer); }
public String fileNameById(long fileId) { fileId = checkFileIdCompatibility(fileId, storageId); final FileChanges fileChanges = this.fileChanges.get(fileId); if (fileChanges != null && fileChanges.fileName != null) { return fileChanges.fileName; } if (deletedFiles.contains(fileId)) { throw new OStorageException("File with id " + fileId + " was deleted."); } return writeCache.fileNameById(fileId); }
private void lockFile() throws IOException { try { fileLock = channel.tryLock(); } catch (OverlappingFileLockException e) { OLogManager.instance().warn(this, "File is already locked by other thread", e); } if (fileLock == null) throw new OStorageException("Database is locked by another process, please shutdown process and try again"); }
@Override public final long addFile(final String fileName, final long fileId, final OWriteCache writeCache) { final int intId = extractFileId(fileId); metadataLock.lock(); try { if (files.containsKey(intId)) { throw new OStorageException("File with id " + intId + " already exists."); } if (fileNameIdMap.containsKey(fileName)) { throw new OStorageException(fileName + " already exists."); } files.put(intId, new MemoryFile(id, intId)); fileNameIdMap.put(fileName, intId); fileIdNameMap.put(intId, fileName); return composeFileId(id, intId); } finally { metadataLock.unlock(); } }
public static OCluster createCluster(final String name, final int configurationVersion, final int binaryVersion, final OAbstractPaginatedStorage storage) { if (configurationVersion >= 0 && configurationVersion < 6) { throw new OStorageException("You use deprecated version of storage cluster, " + "this version is not supported in current implementation. Please do export/import or recreate database."); } switch (binaryVersion) { case 0: return new OPaginatedClusterV0(name, storage); case 1: return new OPaginatedClusterV1(name, storage); default: throw new IllegalStateException("Invalid binary version of cluster " + binaryVersion); } } }
@Override public final long addFile(final String fileName, final OWriteCache writeCache) { metadataLock.lock(); try { Integer fileId = fileNameIdMap.get(fileName); if (fileId == null) { counter++; final int id = counter; files.put(id, new MemoryFile(this.id, id)); fileNameIdMap.put(fileName, id); fileId = id; fileIdNameMap.put(fileId, fileName); } else { throw new OStorageException(fileName + " already exists."); } return composeFileId(id, fileId); } finally { metadataLock.unlock(); } }
public void addCluster(OStoragePaginatedClusterConfiguration config) { lock.acquireWriteLock(); try { if (clusters.size() <= config.id) { final int diff = config.id - clusters.size(); for (int i = 0; i < diff; i++) { clusters.add(null); } clusters.add(config); } else { if (clusters.get(config.id) != null) { throw new OStorageException( "Cluster with id " + config.id + " already exists with name '" + clusters.get(config.id).getName() + "'"); } clusters.set(config.id, config); } } finally { lock.releaseWriteLock(); } }
public long addFile(final String fileName) { if (newFileNamesId.containsKey(fileName)) { throw new OStorageException("File with name " + fileName + " already exists."); } final long fileId; final boolean isNew; if (deletedFileNameIdMap.containsKey(fileName)) { fileId = deletedFileNameIdMap.remove(fileName); deletedFiles.remove(fileId); isNew = false; } else { fileId = writeCache.bookFileId(fileName); isNew = true; } newFileNamesId.put(fileName, fileId); final FileChanges fileChanges = new FileChanges(); fileChanges.isNew = isNew; fileChanges.fileName = fileName; fileChanges.maxNewPageIndex = -1; this.fileChanges.put(fileId, fileChanges); return fileId; }
@Override public void flushTillSegment(final long segmentId) { final Future<Void> future = commitExecutor.submit(new FlushTillSegmentTask(segmentId)); try { future.get(); } catch (final Exception e) { throw ODatabaseException.wrapException(new OStorageException("Error during data flush"), e); } }
public void pinPage(final OCacheEntry cacheEntry) { if (deletedFiles.contains(cacheEntry.getFileId())) { throw new OStorageException("File with id " + cacheEntry.getFileId() + " is deleted."); } final FileChanges changesContainer = fileChanges.get(cacheEntry.getFileId()); assert changesContainer != null; final OCacheEntryChanges pageChangesContainer = changesContainer.pageChangesMap.get(cacheEntry.getPageIndex()); assert pageChangesContainer != null; pageChangesContainer.pinPage = true; }