@Override public PListImpl getPList(final String name) throws Exception { if (!isStarted()) { throw new IllegalStateException("Not started"); } intialize(); synchronized (indexLock) { synchronized (this) { PListImpl result = this.persistentLists.get(name); if (result == null) { final PListImpl pl = new PListImpl(this); pl.setName(name); getPageFile() .tx() .execute( new Transaction.Closure<IOException>() { public void execute(Transaction tx) throws IOException { pl.setHeadPageId(tx.allocate().getPageId()); pl.load(tx); metaData.lists.put(tx, name, pl); } }); result = pl; this.persistentLists.put(name, pl); } final PListImpl toLoad = result; getPageFile() .tx() .execute( new Transaction.Closure<IOException>() { public void execute(Transaction tx) throws IOException { toLoad.load(tx); } }); return result; } } }
public void run() { try { if (isStopping()) { return; } final int lastJournalFileId = journal.getLastAppendLocation().getDataFileId(); final Set<Integer> candidates = journal.getFileMap().keySet(); LOG.trace("Full gc candidate set:" + candidates); if (candidates.size() > 1) { // prune current write for (Iterator<Integer> iterator = candidates.iterator(); iterator.hasNext(); ) { if (iterator.next() >= lastJournalFileId) { iterator.remove(); } } List<PListImpl> plists = null; synchronized (indexLock) { synchronized (this) { plists = new ArrayList<PListImpl>(persistentLists.values()); } } for (PListImpl list : plists) { list.claimFileLocations(candidates); if (isStopping()) { return; } LOG.trace( "Remaining gc candidate set after refs from: " + list.getName() + ":" + candidates); } LOG.trace("GC Candidate set:" + candidates); this.journal.removeDataFiles(candidates); } } catch (IOException e) { LOG.error("Exception on periodic cleanup: " + e, e); } }
@Override protected synchronized void doStop(ServiceStopper stopper) throws Exception { if (scheduler != null) { if (PListStoreImpl.class.getSimpleName().equals(scheduler.getName())) { scheduler.stop(); scheduler = null; } } for (PListImpl pl : this.persistentLists.values()) { pl.unload(null); } if (this.pageFile != null) { this.pageFile.unload(); } if (this.journal != null) { journal.close(); } if (this.lockFile != null) { this.lockFile.unlock(); } this.lockFile = null; this.initialized = false; LOG.info(this + " stopped"); }
public void writePayload(PListImpl list, DataOutput dataOut) throws IOException { list.write(dataOut); }
public PListImpl readPayload(DataInput dataIn) throws IOException { PListImpl result = new PListImpl(this.store); result.read(dataIn); return result; }