mirror of https://github.com/apache/lucene.git
tests: don't allow updating same id concurrently
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1150744 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c2df0c51b6
commit
7964cb97b1
|
@ -101,9 +101,11 @@ public class TestRealTimeGet extends SolrTestCaseJ4 {
|
||||||
final AtomicLong operations = new AtomicLong(10000); // number of query operations to perform in total
|
final AtomicLong operations = new AtomicLong(10000); // number of query operations to perform in total
|
||||||
int nReadThreads = 10;
|
int nReadThreads = 10;
|
||||||
|
|
||||||
|
final Object[] syncArr = new Object[ndocs];
|
||||||
|
|
||||||
for (int i=0; i<ndocs; i++) {
|
for (int i=0; i<ndocs; i++) {
|
||||||
model.put(i, -1L);
|
model.put(i, -1L);
|
||||||
|
syncArr[i] = new Object();
|
||||||
}
|
}
|
||||||
committedModel.putAll(model);
|
committedModel.putAll(model);
|
||||||
|
|
||||||
|
@ -119,16 +121,6 @@ public class TestRealTimeGet extends SolrTestCaseJ4 {
|
||||||
public void run() {
|
public void run() {
|
||||||
while (operations.get() > 0) {
|
while (operations.get() > 0) {
|
||||||
int oper = rand.nextInt(100);
|
int oper = rand.nextInt(100);
|
||||||
int id = rand.nextInt(ndocs);
|
|
||||||
Long val = model.get(id);
|
|
||||||
long nextVal = Math.abs(val)+1;
|
|
||||||
|
|
||||||
// set the lastId before we actually change it sometimes to try and
|
|
||||||
// uncover more race conditions between writing and reading
|
|
||||||
boolean before = random.nextBoolean();
|
|
||||||
if (before) {
|
|
||||||
lastId = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oper < commitPercent) {
|
if (oper < commitPercent) {
|
||||||
if (numCommitting.incrementAndGet() <= maxConcurrentCommits) {
|
if (numCommitting.incrementAndGet() <= maxConcurrentCommits) {
|
||||||
|
@ -154,14 +146,35 @@ public class TestRealTimeGet extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
numCommitting.decrementAndGet();
|
numCommitting.decrementAndGet();
|
||||||
} else if (oper < commitPercent + deletePercent) {
|
continue;
|
||||||
assertU("<delete><id>" + id + "</id></delete>");
|
}
|
||||||
model.put(id, -nextVal);
|
|
||||||
} else if (oper < commitPercent + deletePercent + deleteByQueryPercent) {
|
|
||||||
assertU("<delete><query>id:" + id + "</query></delete>");
|
int id = rand.nextInt(ndocs);
|
||||||
model.put(id, -nextVal);
|
Object sync = syncArr[id];
|
||||||
} else {
|
|
||||||
assertU(adoc("id",Integer.toString(id), field, Long.toString(nextVal)));
|
// set the lastId before we actually change it sometimes to try and
|
||||||
|
// uncover more race conditions between writing and reading
|
||||||
|
boolean before = random.nextBoolean();
|
||||||
|
if (before) {
|
||||||
|
lastId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We can't concurrently update the same document and retain our invariants of increasing values
|
||||||
|
// since we can't guarantee what order the updates will be executed.
|
||||||
|
synchronized (sync) {
|
||||||
|
Long val = model.get(id);
|
||||||
|
long nextVal = Math.abs(val)+1;
|
||||||
|
|
||||||
|
if (oper < commitPercent + deletePercent) {
|
||||||
|
assertU("<delete><id>" + id + "</id></delete>");
|
||||||
|
model.put(id, -nextVal);
|
||||||
|
} else if (oper < commitPercent + deletePercent + deleteByQueryPercent) {
|
||||||
|
assertU("<delete><query>id:" + id + "</query></delete>");
|
||||||
|
model.put(id, -nextVal);
|
||||||
|
} else {
|
||||||
|
assertU(adoc("id",Integer.toString(id), field, Long.toString(nextVal)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!before) {
|
if (!before) {
|
||||||
|
@ -181,33 +194,33 @@ public class TestRealTimeGet extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (operations.decrementAndGet() >= 0) {
|
try {
|
||||||
int oper = rand.nextInt(100);
|
while (operations.decrementAndGet() >= 0) {
|
||||||
// bias toward a recently changed doc
|
int oper = rand.nextInt(100);
|
||||||
int id = rand.nextInt(100) < 25 ? lastId : rand.nextInt(ndocs);
|
// bias toward a recently changed doc
|
||||||
|
int id = rand.nextInt(100) < 25 ? lastId : rand.nextInt(ndocs);
|
||||||
|
|
||||||
// when indexing, we update the index, then the model
|
// when indexing, we update the index, then the model
|
||||||
// so when querying, we should first check the model, and then the index
|
// so when querying, we should first check the model, and then the index
|
||||||
|
|
||||||
boolean realTime = rand.nextInt(100) < percentRealtimeQuery;
|
boolean realTime = rand.nextInt(100) < percentRealtimeQuery;
|
||||||
long val;
|
long val;
|
||||||
|
|
||||||
if (realTime) {
|
if (realTime) {
|
||||||
val = model.get(id);
|
val = model.get(id);
|
||||||
} else {
|
} else {
|
||||||
synchronized(TestRealTimeGet.this) {
|
synchronized(TestRealTimeGet.this) {
|
||||||
val = committedModel.get(id);
|
val = committedModel.get(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
SolrQueryRequest sreq;
|
SolrQueryRequest sreq;
|
||||||
if (realTime) {
|
if (realTime) {
|
||||||
sreq = req("wt","json", "qt","/get", "ids",Integer.toString(id));
|
sreq = req("wt","json", "qt","/get", "ids",Integer.toString(id));
|
||||||
} else {
|
} else {
|
||||||
sreq = req("wt","json", "q","id:"+Integer.toString(id), "omitHeader","true");
|
sreq = req("wt","json", "q","id:"+Integer.toString(id), "omitHeader","true");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
String response = h.query(sreq);
|
String response = h.query(sreq);
|
||||||
Map rsp = (Map)ObjectBuilder.fromJSON(response);
|
Map rsp = (Map)ObjectBuilder.fromJSON(response);
|
||||||
List doclist = (List)(((Map)rsp.get("response")).get("docs"));
|
List doclist = (List)(((Map)rsp.get("response")).get("docs"));
|
||||||
|
@ -218,10 +231,13 @@ public class TestRealTimeGet extends SolrTestCaseJ4 {
|
||||||
long foundVal = (Long)(((Map)doclist.get(0)).get(field));
|
long foundVal = (Long)(((Map)doclist.get(0)).get(field));
|
||||||
assertTrue(foundVal >= Math.abs(val));
|
assertTrue(foundVal >= Math.abs(val));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Throwable e) {
|
||||||
|
operations.set(-1L);
|
||||||
|
SolrException.log(log,e);
|
||||||
|
fail(e.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -236,6 +252,7 @@ public class TestRealTimeGet extends SolrTestCaseJ4 {
|
||||||
for (Thread thread : threads) {
|
for (Thread thread : threads) {
|
||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue