Apache Solr open-source search software
SOLR-4661: Admin UI Replication details now correctly displays the current replicable generation/version of the master
Chris M. Hostetterad47f738955c
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex ab22b251a21..cb8517418f0 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -224,6 +224,9 @@ Bug Fixescode is not something Solr itself returned -- eg: from the Servlet Container,or an intermediate HTTP Proxy (hossman)+* SOLR-4661: Admin UI Replication details now correctly displays the current+ replicable generation/version of the master. (hossman)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.javaindex 98f3dcac6fe..84f2cbe9c71 100644--- a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java@@ -78,7 +78,7 @@ import org.slf4j.LoggerFactory;/*** <p> A Handler which provides a REST API for replication and serves replication requests from Slaves. <p/> </p>- * <p>When running on the master, it provides the following commands <ol> <li>Get the current replicatable index version+ * <p>When running on the master, it provides the following commands <ol> <li>Get the current replicable index version* (command=indexversion)</li> <li>Get the list of files for a given index version* (command=filelist&indexversion=<VERSION>)</li> <li>Get full or a part (chunk) of a given index or a config* file (command=filecontent&file=<FILE_NAME>) You can optionally specify an offset and length to get that@@ -96,6 +96,38 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAwprivate static final Logger LOG = LoggerFactory.getLogger(ReplicationHandler.class.getName());SolrCore core;+ private static final class CommitVersionInfo {+ public final long version;+ public final long generation;+ private CommitVersionInfo(long g, long v) {+ generation = g;+ version = v;+ }+ /**+ * builds a CommitVersionInfo data for the specified IndexCommit.+ * Will never be null, ut version and generation may be zero if+ * there are problems extracting them from the commit data+ */+ public static CommitVersionInfo build(IndexCommit commit) {+ long generation = commit.getGeneration();+ long version = 0;+ try {+ final Map<String,String> commitData = commit.getUserData();+ String commitTime = commitData.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);+ if (commitTime != null) {+ try {+ version = Long.parseLong(commitTime);+ } catch (NumberFormatException e) {+ LOG.warn("Version in commitData was not formated correctly: " + commitTime, e);+ }+ }+ } catch (IOException e) {+ LOG.warn("Unable to get version from commitData, commit: " + commit, e);+ }+ return new CommitVersionInfo(generation, version);+ }+ }+private SnapPuller snapPuller;private ReentrantLock snapPullLock = new ReentrantLock();@@ -501,23 +533,20 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAwreturn "$URL$";}- private long[] getIndexVersion() {- long version[] = new long[2];+ /**+ * returns the CommitVersionInfo for the current searcher, or null on error.+ */+ private CommitVersionInfo getIndexVersion() {+ CommitVersionInfo v = null;RefCounted<SolrIndexSearcher> searcher = core.getSearcher();try {- final IndexCommit commit = searcher.get().getIndexReader().getIndexCommit();- final Map<String,String> commitData = commit.getUserData();- String commitTime = commitData.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);- if (commitTime != null) {- version[0] = Long.parseLong(commitTime);- }- version[1] = commit.getGeneration();+ v = CommitVersionInfo.build(searcher.get().getIndexReader().getIndexCommit());} catch (IOException e) {- LOG.warn("Unable to get index version : ", e);+ LOG.warn("Unable to get index commit: ", e);} finally {searcher.decref();}- return version;+ return v;}@Override@@ -526,9 +555,9 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAwNamedList list = super.getStatistics();if (core != null) {list.add("indexSize", NumberUtils.readableSize(getIndexSize()));- long[] versionGen = getIndexVersion();- list.add("indexVersion", versionGen[0]);- list.add(GENERATION, versionGen[1]);+ CommitVersionInfo vInfo = getIndexVersion();+ list.add("indexVersion", null == vInfo ? 0 : vInfo.version);+ list.add(GENERATION, null == vInfo ? 0 : vInfo.generation);list.add("indexPath", core.getIndexDir());list.add("isMaster", String.valueOf(isMaster));@@ -582,10 +611,10 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAwdetails.add(CMD_SHOW_COMMITS, getCommits());details.add("isMaster", String.valueOf(isMaster));details.add("isSlave", String.valueOf(isSlave));- long[] versionAndGeneration = getIndexVersion();- details.add("indexVersion", versionAndGeneration[0]);- details.add(GENERATION, versionAndGeneration[1]);-+ CommitVersionInfo vInfo = getIndexVersion();+ details.add("indexVersion", null == vInfo ? 0 : vInfo.version);+ details.add(GENERATION, null == vInfo ? 0 : vInfo.generation);+IndexCommit commit = indexCommitPoint; // make a copy so it won't changeif (isMaster) {@@ -595,7 +624,9 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw}if (isMaster && commit != null) {- master.add("replicatableGeneration", commit.getGeneration());+ CommitVersionInfo repCommitInfo = CommitVersionInfo.build(commit);+ master.add("replicableVersion", repCommitInfo.version);+ master.add("replicableGeneration", repCommitInfo.generation);}SnapPuller snapPuller = tempSnapPuller;diff --git a/solr/webapp/web/css/styles/replication.css b/solr/webapp/web/css/styles/replication.cssindex f8cd5b48c57..3d8f0219435 100644--- a/solr/webapp/web/css/styles/replication.css+++ b/solr/webapp/web/css/styles/replication.css@@ -283,6 +283,7 @@#content #replication #details table{+ margin-left: 20px;border-collapse: collapse;}@@ -339,6 +340,7 @@{padding-right: 10px;text-align: right;+ white-space: nowrap;}#content #replication #details table tbody .sizediff --git a/solr/webapp/web/js/scripts/dashboard.js b/solr/webapp/web/js/scripts/dashboard.jsindex 53b426cef2d..4b4bcda9cdf 100644--- a/solr/webapp/web/js/scripts/dashboard.js+++ b/solr/webapp/web/js/scripts/dashboard.js@@ -256,7 +256,8 @@ sammy.getvar is_slave = 'undefined' !== typeof( data.slave );var headline = $( 'h2 span', this );var details_element = $( '#details', this );- var current_type_element = $( ( is_slave ? '.slave' : '.master' ), this );+ var current_type_element = $( ( is_slave ? '.slave' : '.masterSearch' ), this );+ var master_data = is_slave ? data.slave.masterDetails : data;if( is_slave ){@@ -275,6 +276,7 @@ sammy.get.html( headline.html() + ' (Master)' );}+ // the currently searchable commit regardless of type$( '.version div', current_type_element ).html( data.indexVersion );$( '.generation div', current_type_element )@@ -282,9 +284,18 @@ sammy.get$( '.size div', current_type_element ).html( data.indexSize );+ // what's replicable on the master+ var master_element = $( '.master', details_element );+ $( '.version div', master_element )+ .html( master_data.master.replicableVersion || '-' );+ $( '.generation div', master_element )+ .html( master_data.master.replicableGeneration || '-' );+ $( '.size div', master_element )+ .html( "-" );+if( is_slave ){- var master_element = $( '.master', details_element );+ var master_element = $( '.masterSearch', details_element );$( '.version div', master_element ).html( data.slave.masterDetails.indexVersion );$( '.generation div', master_element )@@ -292,7 +303,8 @@ sammy.get$( '.size div', master_element ).html( data.slave.masterDetails.indexSize );- if( data.indexVersion !== data.slave.masterDetails.indexVersion )+ // warnings if slave version|gen doesn't match what's replicable+ if( data.indexVersion !== master_data.master.replicableVersion ){$( '.version', details_element ).addClass( 'diff' );@@ -303,7 +315,7 @@ sammy.get.removeClass( 'diff' );}- if( data.generation !== data.slave.masterDetails.generation )+ if( data.generation !== master_data.master.replicableGeneration ){$( '.generation', details_element ).addClass( 'diff' );diff --git a/solr/webapp/web/js/scripts/replication.js b/solr/webapp/web/js/scripts/replication.jsindex b82683ec303..f407f868240 100644--- a/solr/webapp/web/js/scripts/replication.js+++ b/solr/webapp/web/js/scripts/replication.js@@ -246,26 +246,39 @@ var replication_fetch_status = function()}var details_element = $( '#details', replication_element );- var current_type_element = $( ( is_slave ? '.slave' : '.master' ), details_element );+ var current_type_element = $( ( is_slave ? '.slave' : '.masterSearch' ), details_element );+ var master_data = is_slave ? data.slave.masterDetails : data;+ // the currently searchable commit regardless of type$( '.version div', current_type_element ).html( data.indexVersion );$( '.generation div', current_type_element ).html( data.generation );$( '.size div', current_type_element ).html( data.indexSize );++ // what's replicable on the master+ var master_element = $( '.master', details_element );+ $( '.version div', master_element )+ .html( master_data.master.replicableVersion || '-' );+ $( '.generation div', master_element )+ .html( master_data.master.replicableGeneration || '-' );+ $( '.size div', master_element )+ .html( "-" );if( is_slave ){- var master_element = $( '.master', details_element );- $( '.version div', master_element )- .html( data.slave.masterDetails.indexVersion );- $( '.generation div', master_element )- .html( data.slave.masterDetails.generation );- $( '.size div', master_element )- .html( data.slave.masterDetails.indexSize );-- if( data.indexVersion !== data.slave.masterDetails.indexVersion )+ // what's searchable on the master+ var master_searchable = $( '.masterSearch', details_element );+ $( '.version div', master_searchable )+ .html( master_data.indexVersion );+ $( '.generation div', master_searchable )+ .html( master_data.generation );+ $( '.size div', master_searchable )+ .html( master_data.indexSize );++ // warnings if slave version|gen doesn't match what's replicable+ if( data.indexVersion !== master_data.master.replicableVersion ){$( '.version', details_element ).addClass( 'diff' );@@ -276,7 +289,7 @@ var replication_fetch_status = function().removeClass( 'diff' );}- if( data.generation !== data.slave.masterDetails.generation )+ if( data.generation !== master_data.master.replicableGeneration ){$( '.generation', details_element ).addClass( 'diff' );@@ -511,4 +524,4 @@ sammy.get});}-);\ No newline at end of file+);diff --git a/solr/webapp/web/tpl/dashboard.html b/solr/webapp/web/tpl/dashboard.htmlindex a79c1f2fb5e..e1bd0a7b7ee 100644--- a/solr/webapp/web/tpl/dashboard.html+++ b/solr/webapp/web/tpl/dashboard.html@@ -103,9 +103,18 @@ limitations under the License.</thead><tbody>+ <tr class="masterSearch">++ <th>Master (Searching)</th>+ <td class="version"><div>x</div></td>+ <td class="generation"><div>y</div></td>+ <td class="size"><div>z</div></td>++ </tr>+<tr class="master">- <th>Master:</th>+ <th>Master (Replicable)</th><td class="version"><div>x</div></td><td class="generation"><div>y</div></td><td class="size"><div>z</div></td>@@ -114,7 +123,7 @@ limitations under the License.<tr class="slave slaveOnly">- <th>Slave:</th>+ <th>Slave (Searching)</th><td class="version"><div>a</div></td><td class="generation"><div>c</div></td><td class="size"><div>c</div></td>diff --git a/solr/webapp/web/tpl/replication.html b/solr/webapp/web/tpl/replication.htmlindex bc8f2122341..2bfdfbdbd8c 100644--- a/solr/webapp/web/tpl/replication.html+++ b/solr/webapp/web/tpl/replication.html@@ -116,9 +116,18 @@ limitations under the License.</thead><tbody>+ <tr class="masterSearch">++ <th>Master (Searching)</th>+ <td class="version"><div></div></td>+ <td class="generation"><div></div></td>+ <td class="size"><div></div></td>++ </tr>+<tr class="master">- <th>Master:</th>+ <th>Master (Replicable)</th><td class="version"><div></div></td><td class="generation"><div></div></td><td class="size"><div></div></td>@@ -127,7 +136,7 @@ limitations under the License.<tr class="slave slaveOnly">- <th>Slave:</th>+ <th>Slave (Searching)</th><td class="version"><div></div></td><td class="generation"><div></div></td><td class="size"><div></div></td>@@ -204,4 +213,4 @@ limitations under the License.</div>-</div>\ No newline at end of file+</div>