Version conflict exception message enhancement (#29432)
Report doc is not found rather on PUT ?version=X rather current version [-1] is different than the one provided Closes #21278
This commit is contained in:
parent
182cf11f37
commit
03d1a7e132
|
@ -38,6 +38,9 @@ public enum VersionType implements Writeable {
|
|||
if (expectedVersion == Versions.MATCH_DELETED) {
|
||||
return "document already exists (current version [" + currentVersion + "])";
|
||||
}
|
||||
if (currentVersion == Versions.NOT_FOUND) {
|
||||
return "document does not exist (expected version [" + expectedVersion + "])";
|
||||
}
|
||||
return "current version [" + currentVersion + "] is different than the one provided [" + expectedVersion + "]";
|
||||
}
|
||||
|
||||
|
@ -48,6 +51,9 @@ public enum VersionType implements Writeable {
|
|||
|
||||
@Override
|
||||
public String explainConflictForReads(long currentVersion, long expectedVersion) {
|
||||
if (currentVersion == Versions.NOT_FOUND) {
|
||||
return "document does not exist (expected version [" + expectedVersion + "])";
|
||||
}
|
||||
return "current version [" + currentVersion + "] is different than the one provided [" + expectedVersion + "]";
|
||||
}
|
||||
|
||||
|
@ -123,6 +129,9 @@ public enum VersionType implements Writeable {
|
|||
|
||||
@Override
|
||||
public String explainConflictForReads(long currentVersion, long expectedVersion) {
|
||||
if (currentVersion == Versions.NOT_FOUND) {
|
||||
return "document does not exist (expected version [" + expectedVersion + "])";
|
||||
}
|
||||
return "current version [" + currentVersion + "] is different than the one provided [" + expectedVersion + "]";
|
||||
}
|
||||
|
||||
|
@ -178,6 +187,9 @@ public enum VersionType implements Writeable {
|
|||
|
||||
@Override
|
||||
public String explainConflictForReads(long currentVersion, long expectedVersion) {
|
||||
if (currentVersion == Versions.NOT_FOUND) {
|
||||
return "document does not exist (expected version [" + expectedVersion + "])";
|
||||
}
|
||||
return "current version [" + currentVersion + "] is different than the one provided [" + expectedVersion + "]";
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,11 @@ public class VersionTypeTests extends ESTestCase {
|
|||
assertFalse(VersionType.INTERNAL.isVersionConflictForWrites(Versions.NOT_FOUND, Versions.MATCH_ANY, randomBoolean()));
|
||||
assertFalse(VersionType.INTERNAL.isVersionConflictForReads(Versions.NOT_FOUND, Versions.MATCH_ANY));
|
||||
|
||||
assertEquals("current version [1] is different than the one provided [2]",
|
||||
VersionType.INTERNAL.explainConflictForReads(1, 2));
|
||||
assertEquals("document does not exist (expected version [2])",
|
||||
VersionType.INTERNAL.explainConflictForReads(Versions.NOT_FOUND, 2));
|
||||
|
||||
// deletes
|
||||
assertFalse(VersionType.INTERNAL.isVersionConflictForWrites(Versions.NOT_FOUND, Versions.MATCH_DELETED, true));
|
||||
assertFalse(VersionType.INTERNAL.isVersionConflictForWrites(10, Versions.MATCH_DELETED, true));
|
||||
|
@ -70,6 +75,11 @@ public class VersionTypeTests extends ESTestCase {
|
|||
assertTrue(VersionType.EXTERNAL.validateVersionForReads(randomIntBetween(1, Integer.MAX_VALUE)));
|
||||
assertFalse(VersionType.EXTERNAL.validateVersionForReads(randomIntBetween(Integer.MIN_VALUE, -1)));
|
||||
|
||||
assertEquals("current version [1] is different than the one provided [2]",
|
||||
VersionType.EXTERNAL.explainConflictForReads(1, 2));
|
||||
assertEquals("document does not exist (expected version [2])",
|
||||
VersionType.EXTERNAL.explainConflictForReads(Versions.NOT_FOUND, 2));
|
||||
|
||||
assertTrue(VersionType.EXTERNAL_GTE.validateVersionForWrites(randomIntBetween(1, Integer.MAX_VALUE)));
|
||||
assertFalse(VersionType.EXTERNAL_GTE.validateVersionForWrites(Versions.MATCH_ANY));
|
||||
assertFalse(VersionType.EXTERNAL_GTE.validateVersionForWrites(randomIntBetween(Integer.MIN_VALUE, 0)));
|
||||
|
@ -77,6 +87,11 @@ public class VersionTypeTests extends ESTestCase {
|
|||
assertTrue(VersionType.EXTERNAL_GTE.validateVersionForReads(randomIntBetween(1, Integer.MAX_VALUE)));
|
||||
assertFalse(VersionType.EXTERNAL_GTE.validateVersionForReads(randomIntBetween(Integer.MIN_VALUE, -1)));
|
||||
|
||||
assertEquals("current version [1] is different than the one provided [2]",
|
||||
VersionType.EXTERNAL_GTE.explainConflictForReads(1, 2));
|
||||
assertEquals("document does not exist (expected version [2])",
|
||||
VersionType.EXTERNAL_GTE.explainConflictForReads(Versions.NOT_FOUND, 2));
|
||||
|
||||
assertTrue(VersionType.INTERNAL.validateVersionForWrites(randomIntBetween(1, Integer.MAX_VALUE)));
|
||||
assertTrue(VersionType.INTERNAL.validateVersionForWrites(Versions.MATCH_ANY));
|
||||
assertFalse(VersionType.INTERNAL.validateVersionForWrites(randomIntBetween(Integer.MIN_VALUE, 0)));
|
||||
|
|
Loading…
Reference in New Issue