minor cleanups

This commit is contained in:
Simon Willnauer 2015-05-19 10:23:18 +02:00
parent 8a3d504efb
commit 09283cf7d3
2 changed files with 13 additions and 11 deletions

View File

@ -693,14 +693,13 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
}
public MetadataSnapshot(StreamInput in) throws IOException {
int size = in.readVInt();
ImmutableMap.Builder<String, StoreFileMetaData> metadataBuilder = ImmutableMap.builder();
final int size = in.readVInt();
final ImmutableMap.Builder<String, StoreFileMetaData> metadataBuilder = ImmutableMap.builder();
for (int i = 0; i < size; i++) {
StoreFileMetaData meta = StoreFileMetaData.readStoreFileMetaData(in);
metadataBuilder.put(meta.name(), meta);
}
ImmutableMap.Builder<String, String> commitUserDataBuilder = ImmutableMap.builder();
final ImmutableMap.Builder<String, String> commitUserDataBuilder = ImmutableMap.builder();
int num = in.readVInt();
for (int i = num; i > 0; i--) {
commitUserDataBuilder.put(in.readString(), in.readString());
@ -712,16 +711,19 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
assert metadata.isEmpty() || numSegmentFiles() == 1 : "numSegmentFiles: " + numSegmentFiles();
}
/**
* Returns the number of documents in this store snapshot
*/
public long getNumDocs() {
return numDocs;
}
public static class LoadedMetadata {
ImmutableMap<String, StoreFileMetaData> fileMetadata;
ImmutableMap<String, String> userData;
long numDocs;
static class LoadedMetadata {
final ImmutableMap<String, StoreFileMetaData> fileMetadata;
final ImmutableMap<String, String> userData;
final long numDocs;
public LoadedMetadata(ImmutableMap<String, StoreFileMetaData> fileMetadata, ImmutableMap<String, String> userData, long numDocs) {
LoadedMetadata(ImmutableMap<String, StoreFileMetaData> fileMetadata, ImmutableMap<String, String> userData, long numDocs) {
this.fileMetadata = fileMetadata;
this.userData = userData;
this.numDocs = numDocs;

View File

@ -210,8 +210,8 @@ public class RecoverySourceHandler {
final boolean recoverWithSyncId = recoverySourceSyncId != null &&
recoverySourceSyncId.equals(recoveryTargetSyncId);
if (recoverWithSyncId) {
long numDocsTarget = request.metadataSnapshot().getNumDocs();
long numDocsSource = recoverySourceMetadata.getNumDocs();
final long numDocsTarget = request.metadataSnapshot().getNumDocs();
final long numDocsSource = recoverySourceMetadata.getNumDocs();
if (numDocsTarget != numDocsSource) {
throw new IllegalStateException("try to recover " + request.shardId() + " from primary shard with sync id but number of docs differ: " + numDocsTarget + " (" + request.sourceNode().getName() + ", primary) vs " + numDocsSource + "(" + request.targetNode().getName() + ")");
}