From ad47f738955c59eb625866114a5a57d2e8fe4cd0 Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Wed, 17 Apr 2013 21:13:20 +0000 Subject: [PATCH] SOLR-4661: Admin UI Replication details now correctly displays the current replicable generation/version of the master git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1469073 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 + .../solr/handler/ReplicationHandler.java | 71 +++++++++++++------ solr/webapp/web/css/styles/replication.css | 2 + solr/webapp/web/js/scripts/dashboard.js | 20 ++++-- solr/webapp/web/js/scripts/replication.js | 37 ++++++---- solr/webapp/web/tpl/dashboard.html | 13 +++- solr/webapp/web/tpl/replication.html | 15 +++- 7 files changed, 120 insertions(+), 41 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index ab22b251a21..cb8517418f0 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -224,6 +224,9 @@ Bug Fixes code 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.java index 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; /** *

A Handler which provides a REST API for replication and serves replication requests from Slaves.

- *

When running on the master, it provides the following commands

  1. Get the current replicatable index version + *

    When running on the master, it provides the following commands

    1. Get the current replicable index version * (command=indexversion)
    2. Get the list of files for a given index version * (command=filelist&indexversion=<VERSION>)
    3. 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 SolrCoreAw private 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 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 SolrCoreAw return "$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 searcher = core.getSearcher(); try { - final IndexCommit commit = searcher.get().getIndexReader().getIndexCommit(); - final Map 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 SolrCoreAw NamedList 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 SolrCoreAw details.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 change if (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.css index 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 .size diff --git a/solr/webapp/web/js/scripts/dashboard.js b/solr/webapp/web/js/scripts/dashboard.js index 53b426cef2d..4b4bcda9cdf 100644 --- a/solr/webapp/web/js/scripts/dashboard.js +++ b/solr/webapp/web/js/scripts/dashboard.js @@ -256,7 +256,8 @@ sammy.get var 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.js index 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.html index 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. + + + Master (Searching) +
      x
      +
      y
      +
      z
      + + + - Master: + Master (Replicable)
      x
      y
      z
      @@ -114,7 +123,7 @@ limitations under the License. - Slave: + Slave (Searching)
      a
      c
      c
      diff --git a/solr/webapp/web/tpl/replication.html b/solr/webapp/web/tpl/replication.html index 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. + + + Master (Searching) +
      +
      +
      + + + - Master: + Master (Replicable)
      @@ -127,7 +136,7 @@ limitations under the License. - Slave: + Slave (Searching)
      @@ -204,4 +213,4 @@ limitations under the License. - \ No newline at end of file +