List of usage examples for org.apache.lucene.index IndexCommit getUserData
public abstract Map<String, String> getUserData() throws IOException;
From source file:com.github.rnewson.couchdb.lucene.DatabaseIndexer.java
License:Apache License
private UpdateSequence getUpdateSequence(final Directory dir) throws IOException { if (!DirectoryReader.indexExists(dir)) { return UpdateSequence.START; }// ww w.j ava 2s . co m final List<IndexCommit> commits = DirectoryReader.listCommits(dir); final IndexCommit latest = commits.get(commits.size() - 1); return getUpdateSequence(latest.getUserData()); }
From source file:org.apache.solr.cloud.ReplicateFromLeader.java
License:Apache License
public static String getCommitVersion(SolrCore solrCore) { IndexCommit commit = solrCore.getDeletionPolicy().getLatestCommit(); try {/*from w ww . j av a 2 s.c o m*/ String commitVersion = commit.getUserData().get(SolrIndexWriter.COMMIT_COMMAND_VERSION); if (commitVersion == null) return null; else return commitVersion; } catch (Exception e) { LOG.warn("Cannot get commit command version from index commit point ", e); return null; } }
From source file:org.apache.solr.core.IndexDeletionPolicyWrapper.java
License:Apache License
public static long getCommitTimestamp(IndexCommit commit) throws IOException { final Map<String, String> commitData = commit.getUserData(); String commitTime = commitData.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY); if (commitTime != null) { return Long.parseLong(commitTime); } else {/* w w w .j a v a 2 s. c o m*/ return 0; } }
From source file:org.elasticsearch.index.engine.CombinedDeletionPolicy.java
License:Apache License
private void setLastCommittedTranslogGeneration(List<? extends IndexCommit> commits) throws IOException { // when opening an existing lucene index, we currently always open the last commit. // we therefore use the translog gen as the one that will be required for recovery final IndexCommit indexCommit = commits.get(commits.size() - 1); assert indexCommit.isDeleted() == false : "last commit is deleted"; long minGen = Long.parseLong(indexCommit.getUserData().get(Translog.TRANSLOG_GENERATION_KEY)); translogDeletionPolicy.setMinTranslogGenerationForRecovery(minGen); }
From source file:org.elasticsearch.index.engine.CombinedDeletionPolicyTests.java
License:Apache License
IndexCommit mockIndexCommitWithTranslogGen(long gen) throws IOException { IndexCommit commit = mock(IndexCommit.class); when(commit.getUserData()) .thenReturn(Collections.singletonMap(Translog.TRANSLOG_GENERATION_KEY, Long.toString(gen))); return commit; }
From source file:org.elasticsearch.index.translog.TestTranslog.java
License:Apache License
/** * Lists all existing commits in a given index path, then read the minimum translog generation that will be used in recoverFromTranslog. */// w w w. j av a 2 s . co m private static long minTranslogGenUsedInRecovery(Path translogPath) throws IOException { try (NIOFSDirectory directory = new NIOFSDirectory(translogPath.getParent().resolve("index"))) { List<IndexCommit> commits = DirectoryReader.listCommits(directory); final String translogUUID = commits.get(commits.size() - 1).getUserData() .get(Translog.TRANSLOG_UUID_KEY); long globalCheckpoint = Translog.readGlobalCheckpoint(translogPath, translogUUID); IndexCommit recoveringCommit = CombinedDeletionPolicy.findSafeCommitPoint(commits, globalCheckpoint); return Long.parseLong(recoveringCommit.getUserData().get(Translog.TRANSLOG_GENERATION_KEY)); } }
From source file:org.eu.bitzone.Leia.java
License:Apache License
public void actionCommit() { if (ir == null) { showStatus(MSG_NOINDEX);/*from www . ja va 2 s . c o m*/ return; } if (!(ir instanceof DirectoryReader)) { showStatus("Commit not possible with " + ir.getClass().getSimpleName()); return; } if (readOnly) { showStatus(MSG_READONLY); return; } try { final IndexCommit commit = ((DirectoryReader) ir).getIndexCommit(); final Map<String, String> userData = commit.getUserData(); final TreeMap<String, String> ud = new TreeMap<String, String>(userData); final Object dialog = addComponent(this, "/xml/commit.xml", null, null); putProperty(dialog, "userData", ud); _showUserData(dialog); } catch (final Exception e) { errorMsg("Exception retrieving user data: " + e.toString()); } }
From source file:org.eu.bitzone.Leia.java
License:Apache License
/** * Initialize index overview and other GUI elements. This method is called always when a new index is open. *//*from w ww .j av a 2 s .co m*/ private void initOverview() { try { initSolrTypes(); courier = new Font("Courier", getFont().getStyle(), getFont().getSize()); lastST = find("lastST"); setBoolean(find("bReload"), "enabled", true); setBoolean(find("bClose"), "enabled", true); setBoolean(find("bCommit"), "enabled", true); final Object sTable = find("sTable"); removeAll(sTable); final Object docTable = find("docTable"); removeAll(docTable); final Object cbType = find("cbType"); populateAnalyzers(cbType); final Object pOver = find("pOver"); Object iName = find("idx"); String idxName; if (pName.length() > 40) { idxName = pName.substring(0, 10) + "..." + pName.substring(pName.length() - 27); } else { idxName = pName; } setString(iName, "text", idxName + (readOnly ? " (R)" : "")); iName = find(pOver, "iName"); setString(iName, "text", pName + (readOnly ? " (Read-Only)" : "")); final Object dirImpl = find("dirImpl"); String implName = "N/A"; if (dir == null) { if (ir != null) { implName = "N/A (reader is " + ir.getClass().getName() + ")"; } } else { implName = dir.getClass().getName(); } setString(dirImpl, "text", implName); final Object fileSize = find("iFileSize"); final long totalFileSize = Util.calcTotalFileSize(pName, dir); setString(fileSize, "text", Util.normalizeSize(totalFileSize) + Util.normalizeUnit(totalFileSize)); final Object iFormat = find(pOver, "iFormat"); final Object iCaps = find(pOver, "iCaps"); String formatText = "N/A"; String formatCaps = "N/A"; if (dir != null) { final IndexGate.FormatDetails formatDetails = IndexGate.getIndexFormat(dir); formatText = formatDetails.genericName; formatCaps = formatDetails.capabilities; } setString(iFormat, "text", formatText); setString(iCaps, "text", formatCaps); if (ir == null) { return; } // we need IndexReader from now on idxInfo = new IndexInfo(ir, pName); Object iDocs = find(pOver, "iDocs"); final String numdocs = String.valueOf(ir.numDocs()); setString(iDocs, "text", numdocs); iDocs = find("iDocs1"); setString(iDocs, "text", String.valueOf(ir.maxDoc() - 1)); final Object iFields = find(pOver, "iFields"); fn = idxInfo.getFieldNames(); if (fn.size() == 0) { showStatus("Empty index."); } showFiles(dir, null); if (ir instanceof CompositeReader) { ar = SlowCompositeReaderWrapper.wrap((CompositeReader) ir); } else if (ir instanceof AtomicReader) { ar = (AtomicReader) ir; } if (ar != null) { infos = ar.getFieldInfos(); } showCommits(); final Object fList = find(pOver, "fList"); final Object defFld = find("defFld"); final Object fCombo = find("fCombo"); final TreeSet<String> fields = new TreeSet<String>(fn); idxFields = fields.toArray(new String[fields.size()]); setString(iFields, "text", String.valueOf(idxFields.length)); final Object iTerms = find(pOver, "iTerms"); if (!slowAccess) { final Thread t = new Thread() { @Override public void run() { final Object r = create("row"); final Object cell = create("cell"); add(r, cell); add(fList, r); setBoolean(cell, "enabled", false); setString(cell, "text", "..wait.."); try { numTerms = idxInfo.getNumTerms(); termCounts = idxInfo.getFieldTermCounts(); setString(iTerms, "text", String.valueOf(numTerms)); initFieldList(fList, fCombo, defFld); } catch (final Exception e) { e.printStackTrace(); numTerms = -1; termCounts = Collections.emptyMap(); showStatus("ERROR: can't count terms per field"); } } }; t.start(); } else { setString(iTerms, "text", "N/A"); initFieldList(fList, fCombo, defFld); } final Object iDel = find(pOver, "iDelOpt"); final String sDel = ir.hasDeletions() ? "Yes (" + ir.numDeletedDocs() + ")" : "No"; final IndexCommit ic = ir instanceof DirectoryReader ? ((DirectoryReader) ir).getIndexCommit() : null; final String opt = ic != null ? ic.getSegmentCount() == 1 ? "Yes" : "No" : "?"; final String sDelOpt = sDel + " / " + opt; setString(iDel, "text", sDelOpt); final Object iVer = find(pOver, "iVer"); String verText = "N/A"; if (ic != null) { verText = Long.toHexString(((DirectoryReader) ir).getVersion()); } setString(iVer, "text", verText); final Object iTiiDiv = find(pOver, "iTiiDiv"); String divText = "N/A"; if (ir instanceof DirectoryReader) { final List<AtomicReaderContext> contexts = ir.leaves(); if (contexts.size() > 0 && contexts.get(0).reader() instanceof SegmentReader) { divText = String.valueOf(((SegmentReader) contexts.get(0).reader()).getTermInfosIndexDivisor()); } } setString(iTiiDiv, "text", divText); final Object iCommit = find(pOver, "iCommit"); String commitText = "N/A"; if (ic != null) { commitText = ic.getSegmentsFileName() + " (generation=" + ic.getGeneration() + ", segs=" + ic.getSegmentCount() + ")"; } setString(iCommit, "text", commitText); final Object iUser = find(pOver, "iUser"); String userData = null; if (ic != null) { final Map<String, String> userDataMap = ic.getUserData(); if (userDataMap != null && !userDataMap.isEmpty()) { userData = userDataMap.toString(); } else { userData = "--"; } } else { userData = "(not supported)"; } setString(iUser, "text", userData); final Object nTerms = find("nTerms"); if (!slowAccess) { final Thread t = new Thread() { @Override public void run() { actionTopTerms(nTerms); } }; t.start(); } } catch (final Exception e) { e.printStackTrace(); errorMsg(e.getMessage()); } }
From source file:org.eu.bitzone.Leia.java
License:Apache License
private void showCommits() throws Exception { final Object commitsTable = find("commitsTable"); removeAll(commitsTable);// w ww . jav a2 s. com if (dir == null) { final Object row = create("row"); final Object cell = create("cell"); setString(cell, "text", "<not available>"); setBoolean(cell, "enabled", false); add(row, cell); add(commitsTable, row); return; } final List<IndexCommit> commits = DirectoryReader.listCommits(dir); final IndexCommit current = ir instanceof DirectoryReader ? ((DirectoryReader) ir).getIndexCommit() : null; // commits are ordered from oldest to newest ? final Iterator<IndexCommit> it = commits.iterator(); int rowNum = 0; while (it.hasNext()) { final IndexCommit commit = it.next(); // figure out the name of the segment files final Collection<String> files = commit.getFileNames(); final Iterator<String> itf = files.iterator(); final Object row = create("row"); final boolean enabled = rowNum < commits.size() - 1; final Color color = Color.BLUE; rowNum++; add(commitsTable, row); putProperty(row, "commit", commit); if (enabled) { putProperty(row, "commitDeletable", Boolean.TRUE); } Object cell = create("cell"); final String gen = String.valueOf(commit.getGeneration()); setString(cell, "text", gen); add(row, cell); cell = create("cell"); setString(cell, "text", commit.isDeleted() ? "Y" : "N"); add(row, cell); cell = create("cell"); setString(cell, "text", String.valueOf(commit.getSegmentCount())); add(row, cell); cell = create("cell"); final Map userData = commit.getUserData(); if (userData != null && !userData.isEmpty()) { setString(cell, "text", userData.toString()); } else { setString(cell, "text", ""); } add(row, cell); if (commit.equals(current)) { final Object[] cells = getItems(row); for (final Object c : cells) { setColor(c, "foreground", color); } } } }
From source file:org.getopt.luke.Luke.java
License:Apache License
public void actionCommit() { if (ir == null) { showStatus(MSG_NOINDEX);/* ww w . ja v a 2 s . com*/ return; } if (!(ir instanceof DirectoryReader)) { showStatus("Commit not possible with " + ir.getClass().getSimpleName()); return; } if (readOnly) { showStatus(MSG_READONLY); return; } try { IndexCommit commit = ((DirectoryReader) ir).getIndexCommit(); Map<String, String> userData = commit.getUserData(); TreeMap<String, String> ud = new TreeMap<String, String>(userData); Object dialog = addComponent(this, "/xml/commit.xml", null, null); putProperty(dialog, "userData", ud); _showUserData(dialog); } catch (Exception e) { errorMsg("Exception retrieving user data: " + e.toString()); } }