You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2019/06/12 22:56:47 UTC
[lucene-solr] branch master updated: SOLR-13347: Add support for
reading/writing UUID from/to TransactionLog (#681)
This is an automated email from the ASF dual-hosted git repository.
noble pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/master by this push:
new 8289609 SOLR-13347: Add support for reading/writing UUID from/to TransactionLog (#681)
8289609 is described below
commit 828960927f5093014ae84ba717a8d442e3afa8fc
Author: Thomas Wöckinger <th...@users.noreply.github.com>
AuthorDate: Thu Jun 13 00:56:41 2019 +0200
SOLR-13347: Add support for reading/writing UUID from/to TransactionLog (#681)
SOLR-13347: Transaction log to natively support UUID types
---
.../org/apache/solr/update/TransactionLog.java | 22 ++++++++++++++-
.../org/apache/solr/update/TransactionLogTest.java | 33 +++++++++++++++++++++-
.../org/apache/solr/common/util/JavaBinCodec.java | 1 +
3 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/update/TransactionLog.java b/solr/core/src/java/org/apache/solr/update/TransactionLog.java
index a5f55c2..b4db6ef 100644
--- a/solr/core/src/java/org/apache/solr/update/TransactionLog.java
+++ b/solr/core/src/java/org/apache/solr/update/TransactionLog.java
@@ -102,6 +102,7 @@ public class TransactionLog implements Closeable {
};
public class LogCodec extends JavaBinCodec {
+
public LogCodec(JavaBinCodec.ObjectResolver resolver) {
super(resolver);
}
@@ -128,7 +129,7 @@ public class TransactionLog implements Closeable {
public CharSequence readExternString(DataInputInputStream fis) throws IOException {
int idx = readSize(fis);
if (idx != 0) {// idx != 0 is the index of the extern string
- // no need to synchronize globalStringList - it's only updated before the first record is written to the log
+ // no need to synchronize globalStringList - it's only updated before the first record is written to the log
return globalStringList.get(idx - 1);
} else {// idx == 0 means it has a string value
// this shouldn't happen with this codec subclass.
@@ -136,6 +137,25 @@ public class TransactionLog implements Closeable {
}
}
+ @Override
+ protected Object readObject(DataInputInputStream dis) throws IOException {
+ if (UUID == tagByte) {
+ return new java.util.UUID(dis.readLong(), dis.readLong());
+ }
+ return super.readObject(dis);
+ }
+
+ @Override
+ public boolean writePrimitive(Object val) throws IOException {
+ if (val instanceof java.util.UUID) {
+ java.util.UUID uuid = (java.util.UUID) val;
+ daos.writeByte(UUID);
+ daos.writeLong(uuid.getMostSignificantBits());
+ daos.writeLong(uuid.getLeastSignificantBits());
+ return true;
+ }
+ return super.writePrimitive(val);
+ }
}
TransactionLog(File tlogFile, Collection<String> globalStrings) {
diff --git a/solr/core/src/test/org/apache/solr/update/TransactionLogTest.java b/solr/core/src/test/org/apache/solr/update/TransactionLogTest.java
index 167b3b4..594bc89 100644
--- a/solr/core/src/test/org/apache/solr/update/TransactionLogTest.java
+++ b/solr/core/src/test/org/apache/solr/update/TransactionLogTest.java
@@ -18,19 +18,24 @@
package org.apache.solr.update;
import java.io.File;
+import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.List;
import java.util.Locale;
+import java.util.UUID;
import org.apache.solr.SolrTestCase;
import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.update.TransactionLog.LogReader;
import org.junit.Test;
public class TransactionLogTest extends SolrTestCase {
@Test
public void testBigLastAddSize() {
- String tlogFileName = String.format(Locale.ROOT, UpdateLog.LOG_FILENAME_PATTERN, UpdateLog.TLOG_NAME, Long.MAX_VALUE);
+ String tlogFileName = String.format(Locale.ROOT, UpdateLog.LOG_FILENAME_PATTERN, UpdateLog.TLOG_NAME,
+ Long.MAX_VALUE);
Path path = createTempDir();
File logFile = new File(path.toFile(), tlogFileName);
try (TransactionLog transactionLog = new TransactionLog(logFile, new ArrayList<>())) {
@@ -41,4 +46,30 @@ public class TransactionLogTest extends SolrTestCase {
}
}
+ @Test
+ public void testUUID() throws IOException, InterruptedException {
+ String tlogFileName = String.format(Locale.ROOT, UpdateLog.LOG_FILENAME_PATTERN, UpdateLog.TLOG_NAME,
+ Long.MAX_VALUE);
+ Path path = createTempDir();
+ File logFile = new File(path.toFile(), tlogFileName);
+ UUID uuid = UUID.randomUUID();
+ try (TransactionLog tlog = new TransactionLog(logFile, new ArrayList<>())) {
+ tlog.deleteOnClose = false;
+ AddUpdateCommand updateCommand = new AddUpdateCommand(null);
+
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.addField("uuid", uuid);
+ updateCommand.solrDoc = doc;
+
+ tlog.write(updateCommand);
+ }
+
+ try (TransactionLog tlog = new TransactionLog(logFile, new ArrayList<>(), true)) {
+ LogReader reader = tlog.getReader(0);
+ Object entry = reader.next();
+ assertNotNull(entry);
+ SolrInputDocument doc = (SolrInputDocument) ((List<?>) entry).get(2);
+ assertEquals(uuid, (UUID) doc.getFieldValue("uuid"));
+ }
+ }
}
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
index 434e2f9..7d6f2e4 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
@@ -100,6 +100,7 @@ public class JavaBinCodec implements PushWriter {
MAP_ENTRY_ITER = 17,
ENUM_FIELD_VALUE = 18,
MAP_ENTRY = 19,
+ UUID = 20, // This is reserved to be used only in LogCodec
// types that combine tag + length (or other info) in a single byte
TAG_AND_LEN = (byte) (1 << 5),
STR = (byte) (1 << 5),