SOLR-1015 -- Incomplete information in replication admin page and http command response when server is both master and slave i.e. when server is a repeater

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@743729 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2009-02-12 13:25:25 +00:00
parent 71e622d422
commit 1371f5b70b
4 changed files with 143 additions and 96 deletions

View File

@ -258,6 +258,9 @@ Bug Fixes
30. SOLR-1016: HTTP 503 error changes 500 in SolrCore (koji)
31. SOLR-1015: Incomplete information in replication admin page and http command response when server
is both master and slave i.e. when server is a repeater (Akshay Ukey via shalin)
Other Changes
----------------------

View File

@ -82,6 +82,8 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
private boolean replicateOnCommit = false;
private boolean replicateOnStart = false;
private int numTimesReplicated = 0;
private final Map<String, FileInfo> confFileInfoCache = new HashMap<String, FileInfo>();
@ -139,7 +141,8 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
} else if (command.equals(CMD_SHOW_COMMITS)) {
rsp.add(CMD_SHOW_COMMITS, getCommits());
} else if (command.equals(CMD_DETAILS)) {
getReplicationDetails(rsp);
rsp.add(CMD_DETAILS, getReplicationDetails());
RequestHandlerUtils.addExperimentalFormatWarning(rsp);
}
}
@ -443,11 +446,12 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
if (core != null) {
list.add("indexSize", readableSize(getIndexSize()));
long[] versionGen = getIndexVersion();
list.add(CMD_INDEX_VERSION, versionGen[0]);
list.add("indexVersion", versionGen[0]);
list.add(GENERATION, versionGen[1]);
list.add("indexPath", core.getIndexDir());
list.add("isMaster", String.valueOf(isMaster));
list.add("isSlave", String.valueOf(isSlave));
SnapPuller snapPuller = tempSnapPuller;
if (snapPuller != null) {
@ -461,10 +465,16 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
if (isMaster) {
if (includeConfFiles != null)
list.add("confFilesToReplicate", includeConfFiles);
String replicateAfterString="";
if (replicateOnCommit)
list.add(REPLICATE_AFTER, "commit");
replicateAfterString += "commit, ";
if (replicateOnOptimize)
list.add(REPLICATE_AFTER, "optimize");
replicateAfterString += "optimize, ";
if(replicateOnStart)
replicateAfterString += "startup, ";
if(replicateAfterString.lastIndexOf(',') > -1)
replicateAfterString = replicateAfterString.substring(0, replicateAfterString.lastIndexOf(','));
list.add(REPLICATE_AFTER, replicateAfterString);
}
}
return list;
@ -473,23 +483,44 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
/**
* Used for showing statistics and progress information.
*/
void getReplicationDetails(SolrQueryResponse resp) {
NamedList<Object> getReplicationDetails() {
String timeLastReplicated = "", confFilesReplicated = "", confFilesReplicatedTime = "", timesIndexReplicated = "", timesConfigReplicated = "";
NamedList<Object> details = new SimpleOrderedMap<Object>();
NamedList<Object> master = new SimpleOrderedMap<Object>();
NamedList<Object> slave = new SimpleOrderedMap<Object>();
FileInputStream inFile = null;
details.add("indexSize", readableSize(getIndexSize()));
details.add("indexPath", core.getIndexDir());
details.add(CMD_SHOW_COMMITS, getCommits());
details.add("isMaster", String.valueOf(isMaster));
details.add("isSlave", String.valueOf(isSlave));
long[] versionAndGeneration = getIndexVersion();
details.add(CMD_INDEX_VERSION, versionAndGeneration[0]);
details.add("indexVersion", versionAndGeneration[0]);
details.add(GENERATION, versionAndGeneration[1]);
IndexCommit commit = indexCommitPoint; // make a copy so it won't change
if (isMaster && commit != null) {
details.add("replicatable" + CMD_INDEX_VERSION, commit.getVersion());
details.add("replicatable" + GENERATION, commit.getGeneration());
if (isMaster) {
if (includeConfFiles != null)
master.add(CONF_FILES, includeConfFiles);
String replicateAfterString="";
if (replicateOnCommit)
replicateAfterString += "commit, ";
if (replicateOnOptimize)
replicateAfterString += "optimize, ";
if(replicateOnStart)
replicateAfterString += "startup, ";
if(replicateAfterString.lastIndexOf(',') > -1)
replicateAfterString = replicateAfterString.substring(0, replicateAfterString.lastIndexOf(','));
master.add(REPLICATE_AFTER, replicateAfterString);
}
if (isMaster && commit != null) {
master.add("replicatableIndexVersion", commit.getVersion());
master.add("replicatableGeneration", commit.getGeneration());
}
SnapPuller snapPuller = tempSnapPuller;
if (snapPuller != null) {
try {
@ -515,36 +546,36 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
}
try {
NamedList nl = snapPuller.getCommandResponse(CMD_DETAILS);
details.add("masterDetails", nl.get(CMD_DETAILS));
slave.add("masterDetails", nl.get(CMD_DETAILS));
} catch (IOException e) {
LOG.warn("Exception while invoking a 'details' method on master ", e);
}
details.add(MASTER_URL, snapPuller.getMasterUrl());
slave.add(MASTER_URL, snapPuller.getMasterUrl());
if (snapPuller.getPollInterval() != null) {
details.add(SnapPuller.POLL_INTERVAL, snapPuller.getPollInterval());
slave.add(SnapPuller.POLL_INTERVAL, snapPuller.getPollInterval());
}
if (snapPuller.getNextScheduledExecTime() != null && !isPollingDisabled()) {
Date d = new Date(snapPuller.getNextScheduledExecTime());
details.add("nextExecutionAt", d.toString());
slave.add("nextExecutionAt", d.toString());
} else if (isPollingDisabled()) {
details.add("nextExecutionAt", "Polling disabled");
slave.add("nextExecutionAt", "Polling disabled");
} else
details.add("nextExecutionAt", "");
slave.add("nextExecutionAt", "");
if (timeLastReplicated != null && timeLastReplicated.length() > 0) {
Date d = new Date(Long.valueOf(timeLastReplicated));
details.add("indexReplicatedAt", d.toString());
slave.add("indexReplicatedAt", d.toString());
} else {
details.add("indexReplicatedAt", "");
slave.add("indexReplicatedAt", "");
}
details.add("timesIndexReplicated", timesIndexReplicated);
details.add("confFilesReplicated", confFilesReplicated);
details.add("timesConfigReplicated", timesConfigReplicated);
slave.add("timesIndexReplicated", timesIndexReplicated);
slave.add("confFilesReplicated", confFilesReplicated);
slave.add("timesConfigReplicated", timesConfigReplicated);
if (confFilesReplicatedTime != null && confFilesReplicatedTime.length() > 0) {
Date d = new Date(Long.valueOf(confFilesReplicatedTime));
details.add("confFilesReplicatedAt", d.toString());
slave.add("confFilesReplicatedAt", d.toString());
} else {
details.add("confFilesReplicatedAt", confFilesReplicatedTime);
slave.add("confFilesReplicatedAt", confFilesReplicatedTime);
}
try {
@ -563,9 +594,9 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
bytesToDownload += (Long) file.get(SIZE);
}
details.add("filesToDownload", filesToDownload.toString());
details.add("numFilesToDownload", String.valueOf(filesToDownload.size()));
details.add("bytesToDownload", readableSize(bytesToDownload));
slave.add("filesToDownload", filesToDownload.toString());
slave.add("numFilesToDownload", String.valueOf(filesToDownload.size()));
slave.add("bytesToDownload", readableSize(bytesToDownload));
long bytesDownloaded = 0;
List<String> filesDownloaded = new ArrayList<String>();
@ -580,8 +611,8 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
bytesDownloaded += (Long) file.get(SIZE);
}
details.add("filesDownloaded", filesDownloaded.toString());
details.add("numFilesDownloaded", String.valueOf(filesDownloaded.size()));
slave.add("filesDownloaded", filesDownloaded.toString());
slave.add("numFilesDownloaded", String.valueOf(filesDownloaded.size()));
Map<String, Object> currentFile = snapPuller.getCurrentFile();
String currFile = null;
@ -605,9 +636,9 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
timeElapsed = (System.currentTimeMillis() - snapPuller.getReplicationStartTime()) / 1000;
}
if (replicationStartTime != null) {
details.add("replicationStartTime", replicationStartTime.toString());
slave.add("replicationStartTime", replicationStartTime.toString());
}
details.add("timeElapsed", String.valueOf(timeElapsed) + "s");
slave.add("timeElapsed", String.valueOf(timeElapsed) + "s");
if (bytesDownloaded > 0)
estimatedTimeRemaining = ((bytesToDownload - bytesDownloaded) * timeElapsed) / bytesDownloaded;
@ -618,31 +649,25 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
if (timeElapsed > 0)
downloadSpeed = (bytesDownloaded / timeElapsed);
if (currFile != null)
details.add("currentFile", currFile);
details.add("currentFileSize", readableSize(currFileSize));
details.add("currentFileSizeDownloaded", readableSize(currFileSizeDownloaded));
details.add("currentFileSizePercent", String.valueOf(percentDownloaded));
details.add("bytesDownloaded", readableSize(bytesDownloaded));
details.add("totalPercent", String.valueOf(totalPercent));
details.add("timeRemaining", String.valueOf(estimatedTimeRemaining) + "s");
details.add("downloadSpeed", readableSize(downloadSpeed));
details.add("isPollingDisabled", String.valueOf(isPollingDisabled()));
details.add("isReplicating", String.valueOf(isReplicating()));
slave.add("currentFile", currFile);
slave.add("currentFileSize", readableSize(currFileSize));
slave.add("currentFileSizeDownloaded", readableSize(currFileSizeDownloaded));
slave.add("currentFileSizePercent", String.valueOf(percentDownloaded));
slave.add("bytesDownloaded", readableSize(bytesDownloaded));
slave.add("totalPercent", String.valueOf(totalPercent));
slave.add("timeRemaining", String.valueOf(estimatedTimeRemaining) + "s");
slave.add("downloadSpeed", readableSize(downloadSpeed));
slave.add("isPollingDisabled", String.valueOf(isPollingDisabled()));
slave.add("isReplicating", String.valueOf(isReplicating()));
} catch (Exception e) {
LOG.error("Exception while writing details: ", e);
}
}
if (isMaster) {
if (includeConfFiles != null)
details.add(CONF_FILES, includeConfFiles);
if (replicateOnCommit)
details.add(REPLICATE_AFTER, "commit");
if (replicateOnOptimize)
details.add(REPLICATE_AFTER, "optimize");
}
resp.add(CMD_DETAILS, details);
if(isMaster)
details.add("master", master);
if(isSlave)
details.add("slave", slave);
return details;
}
@SuppressWarnings("unchecked")
@ -683,6 +708,7 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
core.getUpdateHandler().registerCommitCallback(getEventListener(snapshotOnCommit, replicateOnCommit));
}
if (replicateAfter.contains("startup")) {
replicateOnStart = true;
RefCounted<SolrIndexSearcher> s = core.getNewestSearcher(false);
try {
if (core.getUpdateHandler() instanceof DirectUpdateHandler2) {

View File

@ -55,12 +55,11 @@ public NamedList executeCommand(String command, SolrCore core, SolrRequestHandle
%>
<%
final SolrRequestHandler rh = core.getRequestHandler("/replication");
NamedList namedlist = executeCommand("details",core,rh);
NamedList detailsMap = (NamedList)namedlist.get("details");
if("false".equals((String)detailsMap.get("isMaster"))){
if(detailsMap != null)
if("true".equals((String)detailsMap.get("isSlave"))){
%>
<meta http-equiv="refresh" content="2"/>
<%}%>
@ -70,11 +69,16 @@ if("false".equals((String)detailsMap.get("isMaster"))){
<body>
<a href=".."><img border="0" align="right" height="78" width="142" src="../solr_small.png" alt="Solr"></a>
<h1>Solr replication (<%= collectionName %>)
<%
if("true".equals((String)detailsMap.get("isMaster")))
if(detailsMap != null){
if( "true".equals(detailsMap.get("isMaster")) && "true".equals(detailsMap.get("isSlave")))
out.println(" Master & Slave");
else if("true".equals(detailsMap.get("isMaster")))
out.println(" Master");
else
else if("true".equals(detailsMap.get("isSlave")))
out.println(" Slave");
}
%></h1>
<%= hostname %>:<%= port %><br/>

View File

@ -19,8 +19,7 @@
<%-- do a verbatim include so we can use the local vars --%>
<%@include file="header.jsp"
%>
<%@include file="header.jsp"%>
<br clear="all">
<table>
@ -31,30 +30,36 @@
%>
<%
if ("false".equals(detailsMap.get("isMaster")))
if (detailsMap != null) {%>
NamedList slave = null, master = null;
if (detailsMap != null)
if ("true".equals(detailsMap.get("isSlave")))
if(detailsMap.get("slave") != null){
slave = (NamedList)detailsMap.get("slave");%>
<tr>
<td>
<strong>Master</strong>
</td>
<td>
<%
out.println((String) detailsMap.get("masterUrl"));
out.println((String) slave.get("masterUrl"));
%>
</td>
</tr>
<tr>
<%
NamedList nl = (NamedList) detailsMap.get("masterDetails");
NamedList nl = (NamedList) slave.get("masterDetails");
if (nl != null) {
long masterVersion = (Long) nl.get("indexversion");
long masterVersion = (Long) nl.get("indexVersion");
long masterGeneration = (Long) nl.get("generation");
long replicatableMasterVer = 0, replicatableMasterGen = 0;
nl = (NamedList) nl.get("master");
if(nl != null){
if (nl.get("replicatableindexversion") != null)
replicatableMasterVer = (Long) nl.get("replicatableindexversion");
if (nl.get("replicatablegeneration") != null)
replicatableMasterGen = (Long) nl.get("replicatablegeneration");
}
%>
<td>
</td>
@ -75,7 +80,7 @@
</td>
<td>
<%
out.println((String) detailsMap.get("pollInterval"));
out.println((String) slave.get("pollInterval"));
%>
</td>
</tr>
@ -88,7 +93,7 @@
<td>
<%
if (detailsMap != null)
out.println("Index Version: " + detailsMap.get("indexversion") + ", Generation: " + detailsMap.get("generation"));
out.println("Index Version: " + detailsMap.get("indexVersion") + ", Generation: " + detailsMap.get("generation"));
%>
</td>
</tr>
@ -113,34 +118,36 @@
</tr>
<%
if (detailsMap != null)
if ("true".equals(detailsMap.get("isMaster")))
if (detailsMap != null) {
if(detailsMap.get("master") != null){
master = (NamedList) detailsMap.get("master");
%>
<tr>
<td></td>
<td>
<%out.println("Config Files To Replicate: " + detailsMap.get("confFiles"));%>
<%out.println("Config Files To Replicate: " + master.get("confFiles"));%>
</td>
</tr>
<tr>
<td></td>
<td>
<%out.println("Trigger Replication On: " + detailsMap.get("replicateAfter")); %>
<%out.println("Trigger Replication On: " + master.get("replicateAfter")); %>
</td>
</tr>
<%}%>
<%
if ("false".equals(detailsMap.get("isMaster")))
if (detailsMap != null) {%>
if ("true".equals(detailsMap.get("isSlave")))
if (slave != null) {%>
<tr>
<td>
</td>
<td>
<%
out.println("Times Replicated Since Startup: " + detailsMap.get("timesIndexReplicated"));
out.println("Times Replicated Since Startup: " + slave.get("timesIndexReplicated"));
%>
</td>
</tr>
@ -150,7 +157,7 @@
</td>
<td>
<%
out.println("Previous Replication Done At: " + detailsMap.get("indexReplicatedAt"));
out.println("Previous Replication Done At: " + slave.get("indexReplicatedAt"));
%>
</td>
</tr>
@ -160,7 +167,7 @@
</td>
<td>
<%
out.println("Config Files Replicated At: " + detailsMap.get("confFilesReplicatedAt"));
out.println("Config Files Replicated At: " + slave.get("confFilesReplicatedAt"));
%>
</td>
</tr>
@ -170,7 +177,7 @@
</td>
<td>
<%
out.println("Config Files Replicated: " + detailsMap.get("confFilesReplicated"));
out.println("Config Files Replicated: " + slave.get("confFilesReplicated"));
%>
</td>
</tr>
@ -180,7 +187,7 @@
</td>
<td>
<%
out.println("Times Config Files Replicated Since Startup: " + detailsMap.get("timesConfigReplicated"));
out.println("Times Config Files Replicated Since Startup: " + slave.get("timesConfigReplicated"));
%>
</td>
</tr>
@ -190,27 +197,31 @@
</td>
<td>
<%
if (detailsMap.get("nextExecutionAt") != null)
if (detailsMap.get("nextExecutionAt") != "")
out.println("Next Replication Cycle At: " + detailsMap.get("nextExecutionAt"));
else if ("true".equals(detailsMap.get("isPollingDisabled")))
if (slave.get("nextExecutionAt") != null)
if (slave.get("nextExecutionAt") != "")
out.println("Next Replication Cycle At: " + slave.get("nextExecutionAt"));
else if ("true".equals(slave.get("isPollingDisabled")))
out.println("Next Replication Cycle At: Polling disabled.");
else {
NamedList nl1 = (NamedList) detailsMap.get("masterDetails");
out.println("Next Replication Cycle At: After " + nl1.get("replicateAfter") + " on master.");
NamedList nl1 = (NamedList) slave.get("masterDetails");
if(nl1 != null){
NamedList nl2 = (NamedList) nl1.get("master");
if(nl2 != null)
out.println("Next Replication Cycle At: After " + nl2.get("replicateAfter") + " on master.");
}
}
%>
</td>
</tr>
<%
if ("true".equals(detailsMap.get("isReplicating"))) {
if ("true".equals(slave.get("isReplicating"))) {
%>
<tr>
<td><strong>Current Replication Status</strong>
<td>
<%out.println("Start Time: " + detailsMap.get("replicationStartTime"));%>
<%out.println("Start Time: " + slave.get("replicationStartTime"));%>
</td>
</tr>
@ -218,7 +229,7 @@
<td></td>
<td>
<%
out.println("Files Downloaded: " + detailsMap.get("numFilesDownloaded") + " / " + detailsMap.get("numFilesToDownload"));%>
out.println("Files Downloaded: " + slave.get("numFilesDownloaded") + " / " + slave.get("numFilesToDownload"));%>
</td>
</tr>
@ -226,7 +237,7 @@
<td></td>
<td>
<%
out.println("Downloaded: " + detailsMap.get("bytesDownloaded") + " / " + detailsMap.get("bytesToDownload") + " [" + detailsMap.get("totalPercent") + "%]");%>
out.println("Downloaded: " + slave.get("bytesDownloaded") + " / " + slave.get("bytesToDownload") + " [" + slave.get("totalPercent") + "%]");%>
</td>
</tr>
@ -234,7 +245,7 @@
<td></td>
<td>
<%
out.println("Downloading File: " + detailsMap.get("currentFile") + ", Downloaded: " + detailsMap.get("currentFileSizeDownloaded") + " / " + detailsMap.get("currentFileSize") + " [" + detailsMap.get("currentFileSizePercent") + "%]");%>
out.println("Downloading File: " + slave.get("currentFile") + ", Downloaded: " + slave.get("currentFileSizeDownloaded") + " / " + slave.get("currentFileSize") + " [" + slave.get("currentFileSizePercent") + "%]");%>
</td>
</tr>
@ -242,7 +253,7 @@
<td></td>
<td>
<%
out.println("Time Elapsed: " + detailsMap.get("timeElapsed") + ", Estimated Time Remaining: " + detailsMap.get("timeRemaining") + ", Speed: " + detailsMap.get("downloadSpeed") + "/s");%>
out.println("Time Elapsed: " + slave.get("timeElapsed") + ", Estimated Time Remaining: " + slave.get("timeRemaining") + ", Speed: " + slave.get("downloadSpeed") + "/s");%>
</td>
</tr>
<%}%>
@ -257,7 +268,8 @@
executeCommand("disablepoll", core, rh);
else if (pollVal.equals("enable"))
executeCommand("enablepoll", core, rh);
if ("false".equals(detailsMap.get("isPollingDisabled"))) {
if(slave != null)
if ("false".equals(slave.get("isPollingDisabled"))) {
%>
<form name=polling method="POST" action="./index.jsp" accept-charset="UTF-8">
@ -267,7 +279,8 @@
<%}%>
<%
if ("true".equals(detailsMap.get("isPollingDisabled"))) {
if(slave != null)
if ("true".equals(slave.get("isPollingDisabled"))) {
%>
<form name=polling method="POST" action="./index.jsp" accept-charset="UTF-8">
@ -289,7 +302,8 @@
<input name="replicateButton" class="stdbutton" type="submit" value="Replicate Now">
</form>
<%
if ("true".equals(detailsMap.get("isReplicating"))) {
if(slave != null)
if ("true".equals(slave.get("isReplicating"))) {
%>
<script type="text/javascript">
document["replicate"].replicateButton.disabled = true;