Unverified 提交 da2b9dbd authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1635 from katzyn/misc

Optimize UUID to VARCHAR conversion and use correct time check in Engine.openSession()
...@@ -106,7 +106,7 @@ public class SequenceOptions { ...@@ -106,7 +106,7 @@ public class SequenceOptions {
* *
* @param sequence the sequence to get default min value. * @param sequence the sequence to get default min value.
* @param session The session to calculate the value. * @param session The session to calculate the value.
* @return max value when the MINVALUE expression is set, otherwise returns default min value. * @return min value when the MINVALUE expression is set, otherwise returns default min value.
*/ */
public Long getMinValue(Sequence sequence, Session session) { public Long getMinValue(Sequence sequence, Session session) {
if (minValue == ValueExpression.getNull() && sequence != null) { if (minValue == ValueExpression.getNull() && sequence != null) {
......
...@@ -196,14 +196,15 @@ public class Engine implements SessionFactory { ...@@ -196,14 +196,15 @@ public class Engine implements SessionFactory {
String cipher = ci.removeProperty("CIPHER", null); String cipher = ci.removeProperty("CIPHER", null);
String init = ci.removeProperty("INIT", null); String init = ci.removeProperty("INIT", null);
Session session; Session session;
for (int i = 0;; i++) { long start = System.nanoTime();
for (;;) {
session = openSession(ci, ifExists, cipher); session = openSession(ci, ifExists, cipher);
if (session != null) { if (session != null) {
break; break;
} }
// we found a database that is currently closing // we found a database that is currently closing
// wait a bit to avoid a busy loop (the method is synchronized) // wait a bit to avoid a busy loop (the method is synchronized)
if (i > 60 * 1000) { if (System.nanoTime() - start > 60_000_000_000L) {
// retry at most 1 minute // retry at most 1 minute
throw DbException.get(ErrorCode.DATABASE_ALREADY_OPEN_1, throw DbException.get(ErrorCode.DATABASE_ALREADY_OPEN_1,
"Waited for database closing longer than 1 minute"); "Waited for database closing longer than 1 minute");
...@@ -211,7 +212,7 @@ public class Engine implements SessionFactory { ...@@ -211,7 +212,7 @@ public class Engine implements SessionFactory {
try { try {
Thread.sleep(1); Thread.sleep(1);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore throw DbException.get(ErrorCode.DATABASE_CALLED_AT_SHUTDOWN);
} }
} }
synchronized (session) { synchronized (session) {
......
...@@ -256,7 +256,7 @@ public final class DataUtils { ...@@ -256,7 +256,7 @@ public final class DataUtils {
*/ */
public static void writeVarInt(OutputStream out, int x) throws IOException { public static void writeVarInt(OutputStream out, int x) throws IOException {
while ((x & ~0x7f) != 0) { while ((x & ~0x7f) != 0) {
out.write((byte) (0x80 | (x & 0x7f))); out.write((byte) (x | 0x80));
x >>>= 7; x >>>= 7;
} }
out.write((byte) x); out.write((byte) x);
...@@ -270,7 +270,7 @@ public final class DataUtils { ...@@ -270,7 +270,7 @@ public final class DataUtils {
*/ */
public static void writeVarInt(ByteBuffer buff, int x) { public static void writeVarInt(ByteBuffer buff, int x) {
while ((x & ~0x7f) != 0) { while ((x & ~0x7f) != 0) {
buff.put((byte) (0x80 | (x & 0x7f))); buff.put((byte) (x | 0x80));
x >>>= 7; x >>>= 7;
} }
buff.put((byte) x); buff.put((byte) x);
...@@ -331,7 +331,7 @@ public final class DataUtils { ...@@ -331,7 +331,7 @@ public final class DataUtils {
*/ */
public static void writeVarLong(ByteBuffer buff, long x) { public static void writeVarLong(ByteBuffer buff, long x) {
while ((x & ~0x7f) != 0) { while ((x & ~0x7f) != 0) {
buff.put((byte) (0x80 | (x & 0x7f))); buff.put((byte) (x | 0x80));
x >>>= 7; x >>>= 7;
} }
buff.put((byte) x); buff.put((byte) x);
...@@ -347,7 +347,7 @@ public final class DataUtils { ...@@ -347,7 +347,7 @@ public final class DataUtils {
public static void writeVarLong(OutputStream out, long x) public static void writeVarLong(OutputStream out, long x)
throws IOException { throws IOException {
while ((x & ~0x7f) != 0) { while ((x & ~0x7f) != 0) {
out.write((byte) (0x80 | (x & 0x7f))); out.write((byte) (x | 0x80));
x >>>= 7; x >>>= 7;
} }
out.write((byte) x); out.write((byte) x);
......
...@@ -1939,7 +1939,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1939,7 +1939,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
if (notificationRequested) { if (notificationRequested) {
synchronized (lock) { synchronized (lock) {
notificationRequested = false; notificationRequested = false;
lock.notifyAll();; lock.notifyAll();
} }
} }
return updatedRootReference; return updatedRootReference;
......
...@@ -27,10 +27,12 @@ class VersionedValueCommitted extends VersionedValue { ...@@ -27,10 +27,12 @@ class VersionedValueCommitted extends VersionedValue {
return value instanceof VersionedValue ? (VersionedValue) value : new VersionedValueCommitted(value); return value instanceof VersionedValue ? (VersionedValue) value : new VersionedValueCommitted(value);
} }
@Override
public Object getCurrentValue() { public Object getCurrentValue() {
return value; return value;
} }
@Override
public Object getCommittedValue() { public Object getCommittedValue() {
return value; return value;
} }
......
...@@ -1224,7 +1224,7 @@ public class Data { ...@@ -1224,7 +1224,7 @@ public class Data {
*/ */
public void writeVarInt(int x) { public void writeVarInt(int x) {
while ((x & ~0x7f) != 0) { while ((x & ~0x7f) != 0) {
data[pos++] = (byte) (0x80 | (x & 0x7f)); data[pos++] = (byte) (x | 0x80);
x >>>= 7; x >>>= 7;
} }
data[pos++] = (byte) x; data[pos++] = (byte) x;
...@@ -1293,7 +1293,7 @@ public class Data { ...@@ -1293,7 +1293,7 @@ public class Data {
*/ */
public void writeVarLong(long x) { public void writeVarLong(long x) {
while ((x & ~0x7f) != 0) { while ((x & ~0x7f) != 0) {
data[pos++] = (byte) ((x & 0x7f) | 0x80); data[pos++] = (byte) (x | 0x80);
x >>>= 7; x >>>= 7;
} }
data[pos++] = (byte) x; data[pos++] = (byte) x;
......
...@@ -375,9 +375,9 @@ public class FileStore { ...@@ -375,9 +375,9 @@ public class FileStore {
* @return the file size * @return the file size
*/ */
public long length() { public long length() {
try {
long len = fileLength; long len = fileLength;
if (ASSERT) { if (ASSERT) {
try {
len = file.size(); len = file.size();
if (len != fileLength) { if (len != fileLength) {
DbException.throwInternalError( DbException.throwInternalError(
...@@ -391,12 +391,12 @@ public class FileStore { ...@@ -391,12 +391,12 @@ public class FileStore {
DbException.throwInternalError( DbException.throwInternalError(
"unaligned file length " + name + " len " + len); "unaligned file length " + name + " len " + len);
} }
}
return len;
} catch (IOException e) { } catch (IOException e) {
throw DbException.convertIOException(e, name); throw DbException.convertIOException(e, name);
} }
} }
return len;
}
/** /**
* Get the current location of the file pointer. * Get the current location of the file pointer.
......
...@@ -1079,6 +1079,26 @@ public class StringUtils { ...@@ -1079,6 +1079,26 @@ public class StringUtils {
return builder; return builder;
} }
/**
* Appends specified number of trailing bytes from unsigned long value to a
* specified string builder.
*
* @param builder
* string builder to append to
* @param x
* value to append
* @param bytes
* number of bytes to append
* @return the specified string builder
*/
public static StringBuilder appendHex(StringBuilder builder, long x, int bytes) {
char[] hex = HEX;
for (int i = bytes * 8; i > 0;) {
builder.append(hex[(int) (x >> (i -= 4)) & 0xf]).append(hex[(int) (x >> (i -= 4)) & 0xf]);
}
return builder;
}
/** /**
* Check if this string is a decimal number. * Check if this string is a decimal number.
* *
......
...@@ -141,29 +141,17 @@ public class ValueUuid extends Value { ...@@ -141,29 +141,17 @@ public class ValueUuid extends Value {
return PRECISION; return PRECISION;
} }
private static void appendHex(StringBuilder buff, long x, int bytes) {
for (int i = bytes * 8 - 4; i >= 0; i -= 8) {
buff.append(Integer.toHexString((int) (x >> i) & 0xf)).
append(Integer.toHexString((int) (x >> (i - 4)) & 0xf));
}
}
@Override @Override
public String getString() { public String getString() {
return addString(new StringBuilder(36)).toString(); return addString(new StringBuilder(36)).toString();
} }
private StringBuilder addString(StringBuilder builder) { private StringBuilder addString(StringBuilder builder) {
appendHex(builder, high >> 32, 4); StringUtils.appendHex(builder, high >> 32, 4).append('-');
builder.append('-'); StringUtils.appendHex(builder, high >> 16, 2).append('-');
appendHex(builder, high >> 16, 2); StringUtils.appendHex(builder, high, 2).append('-');
builder.append('-'); StringUtils.appendHex(builder, low >> 48, 2).append('-');
appendHex(builder, high, 2); return StringUtils.appendHex(builder, low, 6);
builder.append('-');
appendHex(builder, low >> 48, 2);
builder.append('-');
appendHex(builder, low, 6);
return builder;
} }
@Override @Override
......
...@@ -77,11 +77,11 @@ public class TestAuthentication extends TestBase { ...@@ -77,11 +77,11 @@ public class TestAuthentication extends TestBase {
return externalUserPassword; return externalUserPassword;
} }
private String getRealmName() { private static String getRealmName() {
return "testRealm"; return "testRealm";
} }
private String getStaticRoleName() { private static String getStaticRoleName() {
return "staticRole"; return "staticRole";
} }
...@@ -117,7 +117,7 @@ public class TestAuthentication extends TestBase { ...@@ -117,7 +117,7 @@ public class TestAuthentication extends TestBase {
return "jdbc:h2:mem:" + getClass().getSimpleName(); return "jdbc:h2:mem:" + getClass().getSimpleName();
} }
private String getExternalUser() { private static String getExternalUser() {
return "user"; return "user";
} }
......
...@@ -92,12 +92,12 @@ public class TestLIRSMemoryConsumption extends TestDb { ...@@ -92,12 +92,12 @@ public class TestLIRSMemoryConsumption extends TestDb {
} }
} }
private Object createValue(long key) { private static Object createValue(long key) {
// return new Object(); // return new Object();
return new byte[2540]; return new byte[2540];
} }
private int getValueSize(long key) { private static int getValueSize(long key) {
// return 16; // return 16;
return 2560; return 2560;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论