/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
long snapshotCount;
long committedModelClock;
volatile int lastId;
snapshotCount = 0;
committedModelClock = 0;
lastId = 0;
for (int i=0; i<ndocs; i++) {
}
}
// update variables
final int maxConcurrentCommits = _TestUtil.nextInt(random, 1, TEST_NIGHTLY ? 10 : 5); // number of committers at a time... needed if we want to avoid commit errors due to exceeding the max
// query variables
final AtomicLong operations = new AtomicLong(atLeast(50000)); // number of query operations to perform in total
if (VERBOSE) {
}
final RandomIndexWriter writer = new RandomIndexWriter(random, dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
writer.setDoRandomForceMergeAssert(false);
for (int i=0; i<nWriteThreads; i++) {
public void run() {
try {
if (oper < commitPercent) {
long version;
synchronized(TestStressNRT.this) {
version = snapshotCount++;
}
// assertU(h.commit("softCommit","true"));
if (random.nextBoolean()) {
if (VERBOSE) {
}
} else {
if (VERBOSE) {
System.out.println("TEST: " + Thread.currentThread().getName() + ": reopen reader=" + oldReader + " version=" + version);
}
}
} else {
// assertU(commit());
if (VERBOSE) {
System.out.println("TEST: " + Thread.currentThread().getName() + ": commit+reopen reader=" + oldReader + " version=" + version);
}
if (VERBOSE) {
}
}
// Code below assumes newReader comes w/
// extra ref:
}
synchronized(TestStressNRT.this) {
// install the new reader if it's newest (and check the current version since another reader may have already been installed)
//System.out.println(Thread.currentThread().getName() + ": newVersion=" + newReader.getVersion());
if (VERBOSE) {
System.out.println("TEST: " + Thread.currentThread().getName() + ": install new reader=" + newReader);
}
// Silly: forces fieldInfos to be
// loaded so we don't hit IOE on later
// reader.toString
// install this snapshot only if it's newer than the current one
if (version >= committedModelClock) {
if (VERBOSE) {
System.out.println("TEST: " + Thread.currentThread().getName() + ": install new model version=" + version);
}
} else {
if (VERBOSE) {
System.out.println("TEST: " + Thread.currentThread().getName() + ": skip install new model version=" + version);
}
}
} else {
// if the same reader, don't decRef.
if (VERBOSE) {
System.out.println("TEST: " + Thread.currentThread().getName() + ": skip install new reader=" + newReader);
}
}
}
}
} else {
// set the lastId before we actually change it sometimes to try and
// uncover more race conditions between writing and reading
if (before) {
}
// 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) {
// assertU("<delete><id>" + id + "</id></delete>");
// add tombstone first
if (tombstones) {
d.add(new Field("id","-"+Integer.toString(id), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
}
if (VERBOSE) {
System.out.println("TEST: " + Thread.currentThread().getName() + ": term delDocs id:" + id + " nextVal=" + nextVal);
}
//assertU("<delete><query>id:" + id + "</query></delete>");
// add tombstone first
if (tombstones) {
d.add(new Field("id","-"+Integer.toString(id), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
}
if (VERBOSE) {
System.out.println("TEST: " + Thread.currentThread().getName() + ": query delDocs id:" + id + " nextVal=" + nextVal);
}
} else {
// assertU(adoc("id",Integer.toString(id), field, Long.toString(nextVal)));
if (VERBOSE) {
System.out.println("TEST: " + Thread.currentThread().getName() + ": u id:" + id + " val=" + nextVal);
}
if (tombstones) {
// remove tombstone after new addition (this should be optional?)
}
}
}
if (!before) {
}
}
}
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
};
}
for (int i=0; i<nReadThreads; i++) {
public void run() {
try {
// bias toward a recently changed doc
// when indexing, we update the index, then the model
// so when querying, we should first check the model, and then the index
long val;
IndexReader r;
synchronized(TestStressNRT.this) {
r = reader;
r.incRef();
}
if (VERBOSE) {
System.out.println("TEST: " + Thread.currentThread().getName() + ": s id=" + id + " val=" + val + " r=" + r.getVersion());
}
// sreq = req("wt","json", "q","id:"+Integer.toString(id), "omitHeader","true");
// if we couldn't find the doc, look for its tombstone
if (val == -1L) {
// expected... no doc was added yet
r.decRef();
continue;
}
fail("No documents or tombstones found for id " + id + ", expected at least " + val + " reader=" + r);
}
}
// nothing to do - we can't tell anything from a deleted doc without tombstones
} else {
// we should have found the document, or its tombstone
}
}
}
}
r.decRef();
}
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
};
}
}
}
if (VERBOSE) {
}
}
}