private SnapshotImpl getSnapshot(ReadOptions options) { SnapshotImpl snapshot; if (options.snapshot() != null) { snapshot = (SnapshotImpl) options.snapshot(); } else { snapshot = new SnapshotImpl(versions.getCurrent(), versions.getLastSequence()); snapshot.close(); // To avoid holding the snapshot active.. } return snapshot; }
@Override public byte[] get(byte[] key, ReadOptions options) throws DBException { checkBackgroundException(); LookupKey lookupKey; mutex.lock(); try { SnapshotImpl snapshot = getSnapshot(options); lookupKey = new LookupKey(Slices.wrappedBuffer(key), snapshot.getLastSequence()); // First look in the memtable, then in the immutable memtable (if any). LookupResult lookupResult = memTable.get(lookupKey); if (lookupResult != null) { Slice value = lookupResult.getValue(); if (value == null) { return null; } return value.getBytes(); } if (immutableMemTable != null) { lookupResult = immutableMemTable.get(lookupKey); if (lookupResult != null) { Slice value = lookupResult.getValue(); if (value == null) { return null; } return value.getBytes(); } } } finally { mutex.unlock(); } // Not in memTables; try live files in level order LookupResult lookupResult = versions.get(lookupKey); // schedule compaction if necessary mutex.lock(); try { if (versions.needsCompaction()) { maybeScheduleCompaction(); } } finally { mutex.unlock(); } if (lookupResult != null) { Slice value = lookupResult.getValue(); if (value != null) { return value.getBytes(); } } return null; }
private ISnapshot parse( File file, String prefix, Map<String, String> args, IProgressListener listener) throws SnapshotException { List<Parser> parsers = ParserRegistry.matchParser(file.getName()); if (parsers.isEmpty()) parsers.addAll(ParserRegistry.allParsers()); // try all... List<IOException> errors = new ArrayList<IOException>(); for (Parser parser : parsers) { IIndexBuilder indexBuilder = parser.getIndexBuilder(); if (indexBuilder == null) continue; try { indexBuilder.init(file, prefix); XSnapshotInfo snapshotInfo = new XSnapshotInfo(); snapshotInfo.setPath(file.getAbsolutePath()); snapshotInfo.setPrefix(prefix); snapshotInfo.setProperty("$heapFormat", parser.getId()); // $NON-NLS-1$ if (Boolean.parseBoolean(args.get("keep_unreachable_objects"))) // $NON-NLS-1$ { snapshotInfo.setProperty( "keep_unreachable_objects", GCRootInfo.Type.UNREACHABLE); // $NON-NLS-1$ } PreliminaryIndexImpl idx = new PreliminaryIndexImpl(snapshotInfo); indexBuilder.fill(idx, listener); SnapshotImplBuilder builder = new SnapshotImplBuilder(idx.getSnapshotInfo()); int[] purgedMapping = GarbageCleaner.clean(idx, builder, args, listener); indexBuilder.clean(purgedMapping, listener); SnapshotImpl snapshot = builder.create(parser); snapshot.calculateDominatorTree(listener); return snapshot; } catch (IOException ioe) { errors.add(ioe); indexBuilder.cancel(); } catch (Exception e) { indexBuilder.cancel(); throw SnapshotException.rethrow(e); } } throw new SnapshotException( MessageUtil.format(Messages.SnapshotFactoryImpl_Error_NoParserRegistered, file.getName())); }