You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by bo...@apache.org on 2021/07/13 14:31:21 UTC

[impala] 02/02: IMPALA-10724: Add mutable validWriteIdList

This is an automated email from the ASF dual-hosted git repository.

boroknagyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 00c8e157ddcaec3f12a09ef410d8716b3dac03a4
Author: Yu-Wen Lai <yu...@cloudera.com>
AuthorDate: Wed Jun 2 18:41:13 2021 -0700

    IMPALA-10724: Add mutable validWriteIdList
    
    In this patch, we add a new class for manually updating writeIdList.
    In terms of updating writeIdList, we introduce three methods including
    addOpenWriteId, addAbortedWriteIds, and addCommittedWriteIds.
    
    We will use this class in MetastoreEventProcessor for fine-grained
    table refreshing. With the control of writeIdList, we will be able to
    update the transactional table partially and keep it consistent.
    
    There are some restrictions for MutableValidWriteIdList.
    1. We need to mark a writeId open before mark it committed/aborted.
    2. We only allow two writeId state transitions, open -> committed or
    open -> aborted. Any other transition is NOT allowed.
    
    Change-Id: I28e60db0afd5d4398af24449b72abc928421f7c6
    Reviewed-on: http://gerrit.cloudera.org:8080/17538
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
    Reviewed-by: Quanlong Huang <hu...@gmail.com>
---
 .../java/org/apache/impala/catalog/HdfsTable.java  |  11 +-
 .../hive/common/MutableValidReaderWriteIdList.java | 310 +++++++++++++++++++++
 .../hive/common/MutableValidWriteIdList.java       |  45 +++
 .../common/MutableValidReaderWriteIdListTest.java  | 211 ++++++++++++++
 4 files changed, 573 insertions(+), 4 deletions(-)

diff --git a/fe/src/main/java/org/apache/impala/catalog/HdfsTable.java b/fe/src/main/java/org/apache/impala/catalog/HdfsTable.java
index f8bd2f5..9567517 100644
--- a/fe/src/main/java/org/apache/impala/catalog/HdfsTable.java
+++ b/fe/src/main/java/org/apache/impala/catalog/HdfsTable.java
@@ -65,6 +65,8 @@ import org.apache.impala.common.Pair;
 import org.apache.impala.common.PrintUtils;
 import org.apache.impala.compat.MetastoreShim;
 import org.apache.impala.fb.FbFileBlock;
+import org.apache.impala.hive.common.MutableValidReaderWriteIdList;
+import org.apache.impala.hive.common.MutableValidWriteIdList;
 import org.apache.impala.service.BackendConfig;
 import org.apache.impala.thrift.CatalogLookupStatus;
 import org.apache.impala.thrift.CatalogObjectsConstants;
@@ -285,7 +287,7 @@ public class HdfsTable extends Table implements FeFsTable {
 
   // Valid write id list for this table.
   // null in the case that this table is not transactional.
-  protected ValidWriteIdList validWriteIds_ = null;
+  protected MutableValidWriteIdList validWriteIds_ = null;
 
   // Partitions are marked as "dirty" indicating there are in-progress modifications on
   // their metadata. The corresponding partition builder contains the new version of the
@@ -1903,8 +1905,9 @@ public class HdfsTable extends Table implements FeFsTable {
     isMarkedCached_ =
         HdfsCachingUtil.validateCacheParams(getMetaStoreTable().getParameters());
     if (hdfsTable.isSetValid_write_ids()) {
-      validWriteIds_ = MetastoreShim.getValidWriteIdListFromThrift(
-          getFullName(), hdfsTable.getValid_write_ids());
+      validWriteIds_ =
+          new MutableValidReaderWriteIdList(MetastoreShim.getValidWriteIdListFromThrift(
+              getFullName(), hdfsTable.getValid_write_ids()));
     }
   }
 
@@ -2694,7 +2697,7 @@ public class HdfsTable extends Table implements FeFsTable {
         AcidUtils.isTransactionalTable(msTable_.getParameters())) {
       ValidWriteIdList writeIdList = fetchValidWriteIds(client);
       prevWriteIdChanged = writeIdList.toString().equals(validWriteIds_);
-      validWriteIds_ = writeIdList;
+      validWriteIds_ = new MutableValidReaderWriteIdList(writeIdList);
     } else {
       validWriteIds_ = null;
     }
diff --git a/fe/src/main/java/org/apache/impala/hive/common/MutableValidReaderWriteIdList.java b/fe/src/main/java/org/apache/impala/hive/common/MutableValidReaderWriteIdList.java
new file mode 100644
index 0000000..409d8e7
--- /dev/null
+++ b/fe/src/main/java/org/apache/impala/hive/common/MutableValidReaderWriteIdList.java
@@ -0,0 +1,310 @@
+// 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
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+
+package org.apache.impala.hive.common;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.Longs;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.hive.common.ValidWriteIdList;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * This class is a mutable version of ValidReaderWriteIdList. With this class, we can
+ * maintain the writeIdList based on the HMS events coming in. We need to always mark
+ * the writeId as open before to mark it as aborted/committed.
+ * Also note that this class is not thread safe, we should not update one instance by
+ * multiple threads.
+ */
+public class MutableValidReaderWriteIdList implements MutableValidWriteIdList {
+  private static final Logger LOG =
+      LoggerFactory.getLogger(MutableValidReaderWriteIdList.class);
+
+  private String tableName; // Full table name of format <db_name>.<table_name>
+  private List<Long> exceptions;
+  private BitSet abortedBits;
+  private long minOpenWriteId = Long.MAX_VALUE;
+  private long highWatermark;
+
+  public MutableValidReaderWriteIdList(ValidWriteIdList writeIdList) {
+    readFromString(writeIdList.writeToString());
+  }
+
+  @Override
+  public boolean isWriteIdValid(long writeId) {
+    if (writeId > highWatermark) {
+      return false;
+    }
+    return Collections.binarySearch(exceptions, writeId) < 0;
+  }
+
+  @Override
+  public boolean isValidBase(long writeId) {
+    return (writeId < minOpenWriteId) && (writeId <= highWatermark);
+  }
+
+  @Override
+  public RangeResponse isWriteIdRangeValid(long minWriteId, long maxWriteId) {
+    if (minWriteId > highWatermark) {
+      return RangeResponse.NONE;
+    }
+    if (exceptions.size() > 0 && exceptions.get(0) > maxWriteId) {
+      return RangeResponse.ALL;
+    }
+
+    // since the exceptions and the range in question overlap, count the
+    // exceptions in the range
+    long count = Math.max(0, maxWriteId - highWatermark);
+    for (long txn : exceptions) {
+      if (minWriteId <= txn && txn <= maxWriteId) {
+        count += 1;
+      }
+    }
+
+    if (count == 0) {
+      return RangeResponse.ALL;
+    }
+    if (count == (maxWriteId - minWriteId + 1)) {
+      return RangeResponse.NONE;
+    }
+    return RangeResponse.SOME;
+  }
+
+  @Override
+  public String toString() {
+    return writeToString();
+  }
+
+  // Format is <table_name>:<hwm>:<minOpenWriteId>:<open_writeids>:<abort_writeids>
+  @Override
+  public String writeToString() {
+    StringBuilder buf = new StringBuilder();
+    if (tableName == null) {
+      buf.append("null");
+    } else {
+      buf.append(tableName);
+    }
+    buf.append(':');
+    buf.append(highWatermark);
+    buf.append(':');
+    buf.append(minOpenWriteId);
+
+    StringBuilder open = new StringBuilder();
+    StringBuilder abort = new StringBuilder();
+    for (int i = 0; i < exceptions.size(); i++) {
+      if (abortedBits.get(i)) {
+        if (abort.length() > 0) {
+          abort.append(',');
+        }
+        abort.append(exceptions.get(i));
+      } else {
+        if (open.length() > 0) {
+          open.append(',');
+        }
+        open.append(exceptions.get(i));
+      }
+    }
+    buf.append(':');
+    buf.append(open);
+    buf.append(':');
+    buf.append(abort);
+
+    return buf.toString();
+  }
+
+  @Override
+  public void readFromString(String src) {
+    if (src == null || src.length() == 0) {
+      highWatermark = Long.MAX_VALUE;
+      exceptions = new ArrayList<>();
+      abortedBits = new BitSet();
+    } else {
+      String[] values = src.split(":");
+      Preconditions.checkState(values.length >= 3, "Not enough values");
+      tableName = values[0];
+      if (tableName.equalsIgnoreCase("null")) {
+        tableName = null;
+      }
+      highWatermark = Long.parseLong(values[1]);
+      minOpenWriteId = Long.parseLong(values[2]);
+      String[] openWriteIds = new String[0];
+      String[] abortedWriteIds = new String[0];
+      if (values.length < 4) {
+        openWriteIds = new String[0];
+        abortedWriteIds = new String[0];
+      } else if (values.length == 4) {
+        if (!values[3].isEmpty()) {
+          openWriteIds = values[3].split(",");
+        }
+      } else {
+        if (!values[3].isEmpty()) {
+          openWriteIds = values[3].split(",");
+        }
+        if (!values[4].isEmpty()) {
+          abortedWriteIds = values[4].split(",");
+        }
+      }
+      exceptions = new ArrayList<>(openWriteIds.length + abortedWriteIds.length);
+      for (String open : openWriteIds) {
+        exceptions.add(Long.parseLong(open));
+      }
+      for (String abort : abortedWriteIds) {
+        exceptions.add(Long.parseLong(abort));
+      }
+      Collections.sort(exceptions);
+      abortedBits = new BitSet(exceptions.size());
+      for (String abort : abortedWriteIds) {
+        int index = Collections.binarySearch(exceptions, Long.parseLong(abort));
+        abortedBits.set(index);
+      }
+    }
+  }
+
+  @Override
+  public String getTableName() {
+    return tableName;
+  }
+
+  @Override
+  public long getHighWatermark() {
+    return highWatermark;
+  }
+
+  @Override
+  public long[] getInvalidWriteIds() {
+    return Longs.toArray(exceptions);
+  }
+
+  @Override
+  public Long getMinOpenWriteId() {
+    return minOpenWriteId == Long.MAX_VALUE ? null : minOpenWriteId;
+  }
+
+  @Override
+  public boolean isWriteIdAborted(long writeId) {
+    int index = Collections.binarySearch(exceptions, writeId);
+    return index >= 0 && abortedBits.get(index);
+  }
+
+  @Override
+  public RangeResponse isWriteIdRangeAborted(long minWriteId, long maxWriteId) {
+    if (highWatermark < minWriteId) {
+      return RangeResponse.NONE;
+    }
+
+    int count = 0; // number of aborted txns found in exceptions
+
+    // traverse the aborted txns list, starting at first aborted txn index
+    for (int i = abortedBits.nextSetBit(0); i >= 0; i = abortedBits.nextSetBit(i + 1)) {
+      long abortedTxnId = exceptions.get(i);
+      if (abortedTxnId > maxWriteId) { // we've already gone beyond the specified range
+        break;
+      }
+      if (abortedTxnId >= minWriteId && abortedTxnId <= maxWriteId) {
+        count++;
+      }
+    }
+
+    if (count == 0) {
+      return RangeResponse.NONE;
+    }
+    if (count == (maxWriteId - minWriteId + 1)) {
+      return RangeResponse.ALL;
+    }
+    return RangeResponse.SOME;
+  }
+
+  public boolean isWriteIdOpen(long writeId) {
+    int index = Collections.binarySearch(exceptions, writeId);
+    return index >= 0 && !abortedBits.get(index);
+  }
+
+  @Override
+  public void addOpenWriteId(long writeId) {
+    if (writeId <= highWatermark) {
+      LOG.debug("Not adding open write id: {} {}", writeId, highWatermark);
+      return;
+    }
+    for (long currentId = highWatermark + 1; currentId <= writeId; currentId++) {
+      exceptions.add(currentId);
+    }
+    highWatermark = writeId;
+  }
+
+  @Override
+  public void addAbortedWriteIds(List<Long> writeIds) {
+    Preconditions.checkNotNull(writeIds);
+    Preconditions.checkArgument(writeIds.size() > 0);
+    long maxWriteId = Collections.max(writeIds);
+    Preconditions.checkArgument(maxWriteId <= highWatermark,
+        "Should mark write id as open before abort it: %s", maxWriteId);
+    for (long writeId : writeIds) {
+      int index = Collections.binarySearch(exceptions, writeId);
+      // make sure the write id is not committed
+      Preconditions.checkState(index >= 0);
+      abortedBits.set(index);
+    }
+    updateMinOpenWriteId();
+  }
+
+  @Override
+  public void addCommittedWriteIds(List<Long> writeIds) {
+    Preconditions.checkNotNull(writeIds);
+    Preconditions.checkArgument(writeIds.size() > 0);
+    long maxWriteId = Collections.max(writeIds);
+    Preconditions.checkArgument(maxWriteId <= highWatermark,
+        "Should mark write id (%s) as open before commit it", maxWriteId);
+    List<Long> updatedExceptions = new ArrayList<>();
+    BitSet updatedAbortedBits = new BitSet();
+
+    Set<Integer> idxToRemove = new HashSet<>();
+    for (long writeId : writeIds) {
+      int idx = Collections.binarySearch(exceptions, writeId);
+      if (idx >= 0) {
+        // make sure the write id is open rather than aborted
+        Preconditions.checkState(!abortedBits.get(idx));
+        idxToRemove.add(idx);
+      }
+    }
+    for (int idx = 0; idx < exceptions.size(); idx++) {
+      if (idxToRemove.contains(idx)) {
+        continue;
+      }
+      updatedAbortedBits.set(updatedExceptions.size(), abortedBits.get(idx));
+      updatedExceptions.add(exceptions.get(idx));
+    }
+    exceptions = updatedExceptions;
+    abortedBits = updatedAbortedBits;
+    updateMinOpenWriteId();
+  }
+
+  private void updateMinOpenWriteId() {
+    int index = abortedBits.nextClearBit(0);
+    if (index >= exceptions.size()) {
+      minOpenWriteId = Long.MAX_VALUE;
+    } else {
+      minOpenWriteId = exceptions.get(index);
+    }
+  }
+}
diff --git a/fe/src/main/java/org/apache/impala/hive/common/MutableValidWriteIdList.java b/fe/src/main/java/org/apache/impala/hive/common/MutableValidWriteIdList.java
new file mode 100644
index 0000000..2fb7641
--- /dev/null
+++ b/fe/src/main/java/org/apache/impala/hive/common/MutableValidWriteIdList.java
@@ -0,0 +1,45 @@
+// 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
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+
+package org.apache.impala.hive.common;
+
+import org.apache.hadoop.hive.common.ValidWriteIdList;
+
+import java.util.List;
+
+/**
+ * This is the mutable version of ValidWriteIdList
+ */
+public interface MutableValidWriteIdList extends ValidWriteIdList {
+  /**
+   * This method will mark write ids between highWatermark + 1 and writeId inclusive as
+   * open.
+   */
+  void addOpenWriteId(long writeId);
+
+  /**
+   * This method will mark the writeIds as aborted.
+   * Note that we cannot abort a write id that is committed.
+   */
+  void addAbortedWriteIds(List<Long> writeIds);
+
+  /**
+   * This method will mark the writeIds as committed.
+   * Note that we cannot commit a write id that is aborted.
+   */
+  void addCommittedWriteIds(List<Long> writeIds);
+}
diff --git a/fe/src/test/java/org/apache/impala/hive/common/MutableValidReaderWriteIdListTest.java b/fe/src/test/java/org/apache/impala/hive/common/MutableValidReaderWriteIdListTest.java
new file mode 100644
index 0000000..a041dec
--- /dev/null
+++ b/fe/src/test/java/org/apache/impala/hive/common/MutableValidReaderWriteIdListTest.java
@@ -0,0 +1,211 @@
+// 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
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+
+package org.apache.impala.hive.common;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.apache.hadoop.hive.common.ValidReaderWriteIdList;
+import org.apache.hadoop.hive.common.ValidWriteIdList;
+
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Collections;
+
+public class MutableValidReaderWriteIdListTest {
+  private final String tableName = "t1";
+
+  @Test
+  public void noExceptions() {
+    ValidReaderWriteIdList writeIdList = new ValidReaderWriteIdList(
+        tableName, new long[0], new BitSet(), 1, Long.MAX_VALUE);
+    MutableValidReaderWriteIdList mutableWriteIdList =
+        new MutableValidReaderWriteIdList(writeIdList);
+    String str = mutableWriteIdList.writeToString();
+    assertEquals(tableName + ":1:" + Long.MAX_VALUE + "::", str);
+    assertTrue(mutableWriteIdList.isWriteIdValid(1));
+    assertFalse(mutableWriteIdList.isWriteIdValid(2));
+  }
+
+  @Test
+  public void exceptions() {
+    ValidReaderWriteIdList writeIdList =
+        new ValidReaderWriteIdList(tableName, new long[] {2L, 4L}, new BitSet(), 5, 4L);
+    MutableValidReaderWriteIdList mutableWriteIdList =
+        new MutableValidReaderWriteIdList(writeIdList);
+    String str = mutableWriteIdList.writeToString();
+    assertEquals(tableName + ":5:4:2,4:", str);
+    assertTrue(mutableWriteIdList.isWriteIdValid(1));
+    assertFalse(mutableWriteIdList.isWriteIdValid(2));
+    assertTrue(mutableWriteIdList.isWriteIdValid(3));
+    assertFalse(mutableWriteIdList.isWriteIdValid(4));
+    assertTrue(mutableWriteIdList.isWriteIdValid(5));
+    assertFalse(mutableWriteIdList.isWriteIdValid(6));
+  }
+
+  @Test
+  public void testRangeResponse() {
+    long[] exceptions = new long[1000];
+    for (int i = 0; i < 1000; i++) {
+      exceptions[i] = i + 100;
+    }
+    ValidReaderWriteIdList writeIdList =
+        new ValidReaderWriteIdList(tableName, exceptions, new BitSet(), 2000, 900);
+    MutableValidReaderWriteIdList mutableWriteIdList =
+        new MutableValidReaderWriteIdList(writeIdList);
+    for (int i = 0; i < 100; i++) {
+      assertTrue(mutableWriteIdList.isWriteIdValid(i));
+    }
+    assertEquals(ValidWriteIdList.RangeResponse.ALL,
+        mutableWriteIdList.isWriteIdRangeValid(0, 99));
+    for (int i = 100; i < 1100; i++) {
+      assertFalse(mutableWriteIdList.isWriteIdValid(i));
+    }
+    assertEquals(ValidWriteIdList.RangeResponse.NONE,
+        mutableWriteIdList.isWriteIdRangeValid(100, 1099));
+    for (int i = 1100; i < 2001; i++) {
+      assertTrue(mutableWriteIdList.isWriteIdValid(i));
+    }
+    assertFalse(mutableWriteIdList.isWriteIdValid(2001));
+    assertEquals(ValidWriteIdList.RangeResponse.SOME,
+        mutableWriteIdList.isWriteIdRangeValid(1100, 2001));
+
+    // test for aborted write ids
+    BitSet abortedBits = new BitSet();
+    for (int i = 0; i < 1000; i++) {
+      abortedBits.set(i);
+    }
+    writeIdList =
+        new ValidReaderWriteIdList(tableName, exceptions, abortedBits, 2000, 900);
+    mutableWriteIdList = new MutableValidReaderWriteIdList(writeIdList);
+    for (int i = 0; i < 100; i++) {
+      assertFalse(mutableWriteIdList.isWriteIdAborted(i));
+    }
+    assertEquals(ValidWriteIdList.RangeResponse.NONE,
+        mutableWriteIdList.isWriteIdRangeAborted(0, 99));
+    for (int i = 100; i < 1100; i++) {
+      assertTrue(mutableWriteIdList.isWriteIdAborted(i));
+    }
+    assertEquals(ValidWriteIdList.RangeResponse.ALL,
+        mutableWriteIdList.isWriteIdRangeAborted(100, 1099));
+    for (int i = 1100; i < 2000; i++) {
+      assertFalse(mutableWriteIdList.isWriteIdAborted(i));
+    }
+    assertEquals(ValidWriteIdList.RangeResponse.SOME,
+        mutableWriteIdList.isWriteIdRangeAborted(100, 2000));
+  }
+
+  @Test
+  public void testAbortedTxn() {
+    long[] exceptions = {2L, 4L, 6L, 8L, 10L};
+    BitSet bitSet = new BitSet(exceptions.length);
+    bitSet.set(0); // mark writeId "2L" aborted
+    bitSet.set(3); // mark writeId "8L" aborted
+    ValidReaderWriteIdList writeIdList =
+        new ValidReaderWriteIdList(tableName, exceptions, bitSet, 11, 4);
+    MutableValidReaderWriteIdList mutableWriteIdList =
+        new MutableValidReaderWriteIdList(writeIdList);
+
+    assertTrue(mutableWriteIdList.isWriteIdAborted(2));
+    assertFalse(mutableWriteIdList.isWriteIdAborted(4));
+    assertFalse(mutableWriteIdList.isWriteIdAborted(6));
+    assertTrue(mutableWriteIdList.isWriteIdAborted(8));
+    assertFalse(mutableWriteIdList.isWriteIdAborted(10));
+  }
+
+  @Test
+  public void testAddOpenWriteId() {
+    long[] exceptions = {2, 4, 6, 8, 10};
+    BitSet bitSet = new BitSet(exceptions.length);
+    bitSet.set(0); // mark writeId "2L" aborted
+    bitSet.set(3); // mark writeId "8L" aborted
+    ValidReaderWriteIdList writeIdList =
+        new ValidReaderWriteIdList(tableName, exceptions, bitSet, 11, 4);
+    MutableValidReaderWriteIdList mutableWriteIdList =
+        new MutableValidReaderWriteIdList(writeIdList);
+
+    mutableWriteIdList.addOpenWriteId(13);
+    String str = mutableWriteIdList.writeToString();
+    assertEquals(tableName + ":13:4:4,6,10,12,13:2,8", str);
+    assertTrue(mutableWriteIdList.isWriteIdValid(11));
+    assertFalse(mutableWriteIdList.isWriteIdValid(12));
+    assertTrue(mutableWriteIdList.isWriteIdOpen(12));
+    assertFalse(mutableWriteIdList.isWriteIdValid(13));
+    assertTrue(mutableWriteIdList.isWriteIdOpen(13));
+  }
+
+  @Test
+  public void testAddAbortedWriteIds() {
+    long[] exceptions = {2L, 4L, 6L, 8L, 10L};
+    BitSet bitSet = new BitSet(exceptions.length);
+    bitSet.set(0); // mark writeId "2L" aborted
+    bitSet.set(3); // mark writeId "8L" aborted
+    ValidReaderWriteIdList writeIdList =
+        new ValidReaderWriteIdList(tableName, exceptions, bitSet, 11, 4);
+    MutableValidReaderWriteIdList mutableWriteIdList =
+        new MutableValidReaderWriteIdList(writeIdList);
+
+    mutableWriteIdList.addOpenWriteId(13);
+    mutableWriteIdList.addAbortedWriteIds(Collections.singletonList(4L));
+    mutableWriteIdList.addAbortedWriteIds(Collections.singletonList(12L));
+    String str = mutableWriteIdList.writeToString();
+    assertEquals(tableName + ":13:6:6,10,13:2,4,8,12", str);
+    assertFalse(mutableWriteIdList.isWriteIdValid(4));
+    assertTrue(mutableWriteIdList.isWriteIdAborted(4));
+    assertFalse(mutableWriteIdList.isWriteIdValid(12));
+    assertTrue(mutableWriteIdList.isWriteIdAborted(12));
+    assertFalse(mutableWriteIdList.isWriteIdValid(13));
+    assertFalse(mutableWriteIdList.isWriteIdAborted(13));
+  }
+
+  @Test
+  public void testAddCommittedWriteIds() {
+    long[] exceptions = {2L, 4L, 6L, 8L, 10L};
+    BitSet bitSet = new BitSet(exceptions.length);
+    bitSet.set(0); // mark writeId "2L" aborted
+    bitSet.set(3); // mark writeId "8L" aborted
+    ValidReaderWriteIdList writeIdList =
+        new ValidReaderWriteIdList(tableName, exceptions, bitSet, 11, 4);
+    MutableValidReaderWriteIdList mutableWriteIdList =
+        new MutableValidReaderWriteIdList(writeIdList);
+
+    mutableWriteIdList.addCommittedWriteIds(Arrays.asList(4L, 10L));
+    String str = mutableWriteIdList.writeToString();
+    assertEquals(tableName + ":11:6:6:2,8", str);
+    assertTrue(mutableWriteIdList.isWriteIdAborted(2));
+    assertTrue(mutableWriteIdList.isWriteIdValid(4));
+    assertFalse(mutableWriteIdList.isWriteIdValid(6));
+    assertTrue(mutableWriteIdList.isWriteIdValid(10));
+    assertTrue(mutableWriteIdList.isWriteIdValid(11));
+  }
+
+  @Test(expected = IllegalStateException.class)
+  public void testAddAbortedToCommitted() {
+    long[] exceptions = {2L, 4L, 6L, 8L, 10L};
+    BitSet bitSet = new BitSet(exceptions.length);
+    bitSet.set(0); // mark writeId "2L" aborted
+    bitSet.set(3); // mark writeId "8L" aborted
+    ValidReaderWriteIdList writeIdList =
+        new ValidReaderWriteIdList(tableName, exceptions, bitSet, 11, 4);
+    MutableValidReaderWriteIdList mutableWriteIdList =
+        new MutableValidReaderWriteIdList(writeIdList);
+    mutableWriteIdList.addCommittedWriteIds(Collections.singletonList(2L));
+  }
+}
\ No newline at end of file