Reformatted code according to lucene/solr standards

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1543422 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2013-11-19 13:25:12 +00:00
parent d744fb54dc
commit 94fe5db45c
2 changed files with 27 additions and 27 deletions

View File

@ -23,7 +23,6 @@ import org.junit.BeforeClass;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Random;
import java.util.Set; import java.util.Set;
@ -80,7 +79,7 @@ public class TriLevelCompositeIdRoutingTest extends ShardRoutingTest {
// for now, we know how ranges will be distributed to shards. // for now, we know how ranges will be distributed to shards.
// may have to look it up in clusterstate if that assumption changes. // may have to look it up in clusterstate if that assumption changes.
for (int i=0;i < NUM_DOCS;i++) { for (int i = 0; i < NUM_DOCS; i++) {
int appId = r.nextInt(NUM_APPS) + 1; int appId = r.nextInt(NUM_APPS) + 1;
int userId = r.nextInt(NUM_USERS) + 1; int userId = r.nextInt(NUM_USERS) + 1;
@ -93,10 +92,10 @@ public class TriLevelCompositeIdRoutingTest extends ShardRoutingTest {
HashMap<String, Integer> idMap = new HashMap<String, Integer>(); HashMap<String, Integer> idMap = new HashMap<String, Integer>();
for(int i=1;i<=sliceCount;i++) { for (int i = 1; i <= sliceCount; i++) {
Set<String> ids = doQueryGetUniqueIdKeys("q", "*:*", "shards", "shard" + i); Set<String> ids = doQueryGetUniqueIdKeys("q", "*:*", "shards", "shard" + i);
for(String id:ids) { for (String id : ids) {
assertFalse("Found the same route key [" + id + "] in 2 shards.", idMap.containsKey(id)); assertFalse("Found the same route key [" + id + "] in 2 shards.", idMap.containsKey(id));
idMap.put(getKey(id), i); idMap.put(getKey(id), i);
} }
@ -111,7 +110,7 @@ public class TriLevelCompositeIdRoutingTest extends ShardRoutingTest {
// may have to look it up in clusterstate if that assumption changes. // may have to look it up in clusterstate if that assumption changes.
del("*:*"); del("*:*");
for (int i=0;i < NUM_DOCS;i++) { for (int i = 0; i < NUM_DOCS; i++) {
int appId = r.nextInt(NUM_APPS) + 1; int appId = r.nextInt(NUM_APPS) + 1;
int userId = r.nextInt(NUM_USERS) + 1; int userId = r.nextInt(NUM_USERS) + 1;
int bitMask = r.nextInt(16) + 1; int bitMask = r.nextInt(16) + 1;
@ -125,10 +124,10 @@ public class TriLevelCompositeIdRoutingTest extends ShardRoutingTest {
HashMap<String, Integer> idMap = new HashMap<String, Integer>(); HashMap<String, Integer> idMap = new HashMap<String, Integer>();
for(int i=1;i<=sliceCount;i++) { for (int i = 1; i <= sliceCount; i++) {
Set<String> ids = doQueryGetUniqueIdKeys("q", "*:*", "shards", "shard" + i); Set<String> ids = doQueryGetUniqueIdKeys("q", "*:*", "shards", "shard" + i);
for(String id:ids) { for (String id : ids) {
assertFalse("Found the same route key [" + id + "] in 2 shards.", idMap.containsKey(id)); assertFalse("Found the same route key [" + id + "] in 2 shards.", idMap.containsKey(id));
idMap.put(getKey(id), i); idMap.put(getKey(id), i);
} }
@ -137,7 +136,7 @@ public class TriLevelCompositeIdRoutingTest extends ShardRoutingTest {
} }
void doAddDoc(String id) throws Exception { void doAddDoc(String id) throws Exception {
index("id",id); index("id", id);
// todo - target diff servers and use cloud clients as well as non-cloud clients // todo - target diff servers and use cloud clients as well as non-cloud clients
} }

View File

@ -48,7 +48,7 @@ public class CompositeIdRouter extends HashBasedRouter {
if (shardFieldName != null && doc != null) { if (shardFieldName != null && doc != null) {
Object o = doc.getFieldValue(shardFieldName); Object o = doc.getFieldValue(shardFieldName);
if (o == null) if (o == null)
throw new SolrException (SolrException.ErrorCode.BAD_REQUEST, "No value for :"+shardFieldName + ". Unable to identify shard"); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No value for :" + shardFieldName + ". Unable to identify shard");
id = o.toString(); id = o.toString();
} }
if (id.indexOf(SEPARATOR) < 0) { if (id.indexOf(SEPARATOR) < 0) {
@ -61,6 +61,7 @@ public class CompositeIdRouter extends HashBasedRouter {
/** /**
* Get Range for a given CompositeId based route key * Get Range for a given CompositeId based route key
*
* @param routeKey to return Range for * @param routeKey to return Range for
* @return Range for given routeKey * @return Range for given routeKey
*/ */
@ -129,7 +130,7 @@ public class CompositeIdRouter extends HashBasedRouter {
assert max >= min; assert max >= min;
if (partitions == 0) return Collections.EMPTY_LIST; if (partitions == 0) return Collections.EMPTY_LIST;
long rangeSize = (long)max - (long)min; long rangeSize = (long) max - (long) min;
long rangeStep = Math.max(1, rangeSize / partitions); long rangeStep = Math.max(1, rangeSize / partitions);
List<Range> ranges = new ArrayList<Range>(partitions); List<Range> ranges = new ArrayList<Range>(partitions);
@ -145,7 +146,7 @@ public class CompositeIdRouter extends HashBasedRouter {
// With default bits==16, one would need to create more than 4000 shards before this // With default bits==16, one would need to create more than 4000 shards before this
// becomes false by default. // becomes false by default.
int mask = 0x0000ffff; int mask = 0x0000ffff;
boolean round = rangeStep >= (1<<bits)*16; boolean round = rangeStep >= (1 << bits) * 16;
while (end < max) { while (end < max) {
targetEnd = targetStart + rangeStep; targetEnd = targetStart + rangeStep;
@ -154,7 +155,7 @@ public class CompositeIdRouter extends HashBasedRouter {
if (round && ((end & mask) != mask)) { if (round && ((end & mask) != mask)) {
// round up or down? // round up or down?
int increment = 1 << bits; // 0x00010000 int increment = 1 << bits; // 0x00010000
long roundDown = (end | mask) - increment ; long roundDown = (end | mask) - increment;
long roundUp = (end | mask) + increment; long roundUp = (end | mask) + increment;
if (end - roundDown < roundUp - end && roundDown > start) { if (end - roundDown < roundUp - end && roundDown > start) {
end = roundDown; end = roundDown;
@ -167,7 +168,7 @@ public class CompositeIdRouter extends HashBasedRouter {
if (ranges.size() == partitions - 1) { if (ranges.size() == partitions - 1) {
end = max; end = max;
} }
ranges.add(new Range((int)start, (int)end)); ranges.add(new Range((int) start, (int) end));
start = end + 1L; start = end + 1L;
targetStart = targetEnd + 1L; targetStart = targetEnd + 1L;
} }
@ -192,9 +193,9 @@ public class CompositeIdRouter extends HashBasedRouter {
pieces = parts.length; pieces = parts.length;
hashes = new int[pieces]; hashes = new int[pieces];
numBits = new int[2]; numBits = new int[2];
if(key.endsWith("!")) if (key.endsWith("!"))
pieces++; pieces++;
if(pieces == 3) { if (pieces == 3) {
numBits[0] = 8; numBits[0] = 8;
numBits[1] = 8; numBits[1] = 8;
triLevel = true; triLevel = true;
@ -204,10 +205,10 @@ public class CompositeIdRouter extends HashBasedRouter {
} }
for(int i=0;i<parts.length;i++) { for (int i = 0; i < parts.length; i++) {
int commaIdx = parts[i].indexOf(bitsSeparator); int commaIdx = parts[i].indexOf(bitsSeparator);
if(commaIdx > 0) { if (commaIdx > 0) {
numBits[i] = getNumBits(parts[i], commaIdx); numBits[i] = getNumBits(parts[i], commaIdx);
parts[i] = parts[i].substring(0, commaIdx); parts[i] = parts[i].substring(0, commaIdx);
} }
@ -220,7 +221,7 @@ public class CompositeIdRouter extends HashBasedRouter {
int lowerBound; int lowerBound;
int upperBound; int upperBound;
if(triLevel) { if (triLevel) {
lowerBound = hashes[0] & masks[0] | hashes[1] & masks[1]; lowerBound = hashes[0] & masks[0] | hashes[1] & masks[1];
upperBound = lowerBound | masks[2]; upperBound = lowerBound | masks[2];
} else { } else {
@ -245,7 +246,7 @@ public class CompositeIdRouter extends HashBasedRouter {
*/ */
private int[] getMasks() { private int[] getMasks() {
int[] masks; int[] masks;
if(triLevel) if (triLevel)
masks = getBitMasks(numBits[0], numBits[1]); masks = getBitMasks(numBits[0], numBits[1]);
else else
masks = getBitMasks(numBits[0]); masks = getBitMasks(numBits[0]);
@ -256,8 +257,8 @@ public class CompositeIdRouter extends HashBasedRouter {
private int[] getBitMasks(int firstBits, int secondBits) { private int[] getBitMasks(int firstBits, int secondBits) {
// java can't shift 32 bits // java can't shift 32 bits
int[] masks = new int[3]; int[] masks = new int[3];
masks[0] = firstBits==0 ? 0 : (-1 << (32-firstBits)); masks[0] = firstBits == 0 ? 0 : (-1 << (32 - firstBits));
masks[1] = (firstBits + secondBits)==0 ? 0 : (-1 << (32 - firstBits - secondBits)); masks[1] = (firstBits + secondBits) == 0 ? 0 : (-1 << (32 - firstBits - secondBits));
masks[1] = masks[0] ^ masks[1]; masks[1] = masks[0] ^ masks[1];
masks[2] = (firstBits + secondBits) == 32 ? 0 : ~(masks[0] | masks[1]); masks[2] = (firstBits + secondBits) == 32 ? 0 : ~(masks[0] | masks[1]);
return masks; return masks;
@ -265,7 +266,7 @@ public class CompositeIdRouter extends HashBasedRouter {
private int getNumBits(String firstPart, int commaIdx) { private int getNumBits(String firstPart, int commaIdx) {
int v = 0; int v = 0;
for (int idx = commaIdx + 1; idx<firstPart.length(); idx++) { for (int idx = commaIdx + 1; idx < firstPart.length(); idx++) {
char ch = firstPart.charAt(idx); char ch = firstPart.charAt(idx);
if (ch < '0' || ch > '9') return -1; if (ch < '0' || ch > '9') return -1;
v = v * 10 + (ch - '0'); v = v * 10 + (ch - '0');
@ -277,15 +278,15 @@ public class CompositeIdRouter extends HashBasedRouter {
// java can't shift 32 bits // java can't shift 32 bits
int[] masks; int[] masks;
masks = new int[2]; masks = new int[2];
masks[0] = firstBits==0 ? 0 : (-1 << (32-firstBits)); masks[0] = firstBits == 0 ? 0 : (-1 << (32 - firstBits));
masks[1] = firstBits==32 ? 0 : (-1 >>> firstBits); masks[1] = firstBits == 32 ? 0 : (-1 >>> firstBits);
return masks; return masks;
} }
int getHash() { int getHash() {
int result = hashes[0] & masks[0]; int result = hashes[0] & masks[0];
for(int i=1;i<pieces;i++) for (int i = 1; i < pieces; i++)
result = result | (hashes[i] & masks[i]); result = result | (hashes[i] & masks[i]);
return result; return result;
} }