parent
7273948188
commit
7a7f6055dc
|
@ -362,13 +362,12 @@ public class InternalEngine extends Engine {
|
|||
}
|
||||
|
||||
long expectedVersion = index.version();
|
||||
if (index.versionType().isVersionConflictForWrites(currentVersion, expectedVersion, deleted)) {
|
||||
if (index.origin() == Operation.Origin.RECOVERY) {
|
||||
return false;
|
||||
} else {
|
||||
if (isVersionConflictForWrites(index, currentVersion, deleted, expectedVersion)) {
|
||||
if (index.origin() != Operation.Origin.RECOVERY) {
|
||||
throw new VersionConflictEngineException(shardId, index.type(), index.id(),
|
||||
index.versionType().explainConflictForWrites(currentVersion, expectedVersion, deleted));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
long updatedVersion = index.versionType().updateVersion(currentVersion, expectedVersion);
|
||||
|
||||
|
@ -378,12 +377,20 @@ public class InternalEngine extends Engine {
|
|||
if (currentVersion == Versions.NOT_FOUND) {
|
||||
// document does not exists, we can optimize for create
|
||||
created = true;
|
||||
if (index.docs().size() > 1) {
|
||||
indexWriter.addDocuments(index.docs());
|
||||
index(index, indexWriter);
|
||||
} else {
|
||||
indexWriter.addDocument(index.docs().get(0));
|
||||
created = update(index, versionValue, indexWriter);
|
||||
}
|
||||
} else {
|
||||
Translog.Location translogLocation = translog.add(new Translog.Index(index));
|
||||
|
||||
versionMap.putUnderLock(index.uid().bytes(), new VersionValue(updatedVersion, translogLocation));
|
||||
index.setTranslogLocation(translogLocation);
|
||||
return created;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean update(Index index, VersionValue versionValue, IndexWriter indexWriter) throws IOException {
|
||||
boolean created;
|
||||
if (versionValue != null) {
|
||||
created = versionValue.delete(); // we have a delete which is not GC'ed...
|
||||
} else {
|
||||
|
@ -394,13 +401,19 @@ public class InternalEngine extends Engine {
|
|||
} else {
|
||||
indexWriter.updateDocument(index.uid(), index.docs().get(0));
|
||||
}
|
||||
}
|
||||
Translog.Location translogLocation = translog.add(new Translog.Index(index));
|
||||
|
||||
versionMap.putUnderLock(index.uid().bytes(), new VersionValue(updatedVersion, translogLocation));
|
||||
index.setTranslogLocation(translogLocation);
|
||||
return created;
|
||||
}
|
||||
|
||||
private static void index(Index index, IndexWriter indexWriter) throws IOException {
|
||||
if (index.docs().size() > 1) {
|
||||
indexWriter.addDocuments(index.docs());
|
||||
} else {
|
||||
indexWriter.addDocument(index.docs().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isVersionConflictForWrites(Index index, long currentVersion, boolean deleted, long expectedVersion) {
|
||||
return index.versionType().isVersionConflictForWrites(currentVersion, expectedVersion, deleted);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue