You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by td...@apache.org on 2015/12/01 06:56:35 UTC
[3/3] phoenix git commit: PHOENIX-2374 Honor PTable.isWALDisabled()
for row deletes
PHOENIX-2374 Honor PTable.isWALDisabled() for row deletes
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/1928b8fc
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/1928b8fc
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/1928b8fc
Branch: refs/heads/4.x-HBase-0.98
Commit: 1928b8fc4178157bcab526bb6c0a2c3fa1a93154
Parents: 138eac6
Author: James Taylor <jt...@salesforce.com>
Authored: Mon Nov 30 20:07:43 2015 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Mon Nov 30 21:55:59 2015 -0800
----------------------------------------------------------------------
.../org/apache/phoenix/schema/PTableImpl.java | 17 +++--
.../org/apache/phoenix/schema/MutationTest.java | 74 ++++++++++++++++++++
2 files changed, 84 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/1928b8fc/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
index 0827ea7..1805d94 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
@@ -697,12 +697,15 @@ public class PTableImpl implements PTable {
newMutations();
}
- @SuppressWarnings("deprecation")
private void newMutations() {
- this.setValues = new Put(this.key);
- this.unsetValues = new Delete(this.key);
- this.setValues.setWriteToWAL(!isWALDisabled());
- this.unsetValues.setWriteToWAL(!isWALDisabled());
+ Put put = new Put(this.key);
+ Delete delete = new Delete(this.key);
+ if (isWALDisabled()) {
+ put.setDurability(Durability.SKIP_WAL);
+ delete.setDurability(Durability.SKIP_WAL);
+ }
+ this.setValues = put;
+ this.unsetValues = delete;
}
@Override
@@ -781,6 +784,7 @@ public class PTableImpl implements PTable {
}
}
+ @SuppressWarnings("deprecation")
@Override
public void delete() {
newMutations();
@@ -800,8 +804,7 @@ public class PTableImpl implements PTable {
}
deleteRow = delete;
}
- // No need to write to the WAL for indexes
- if (PTableImpl.this.getType() == PTableType.INDEX) {
+ if (isWALDisabled()) {
deleteRow.setDurability(Durability.SKIP_WAL);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/1928b8fc/phoenix-core/src/test/java/org/apache/phoenix/schema/MutationTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/MutationTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/MutationTest.java
new file mode 100644
index 0000000..ccbda54
--- /dev/null
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/MutationTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.phoenix.schema;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.hadoop.hbase.client.Durability;
+import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.query.BaseConnectionlessQueryTest;
+import org.junit.Test;
+
+public class MutationTest extends BaseConnectionlessQueryTest {
+ @Test
+ public void testDurability() throws Exception {
+ testDurability(true);
+ testDurability(false);
+ }
+
+ private void testDurability(boolean disableWAL) throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ try {
+ Durability expectedDurability = disableWAL ? Durability.SKIP_WAL : Durability.USE_DEFAULT;
+ conn.setAutoCommit(false);
+ conn.createStatement().execute("CREATE TABLE t1 (k integer not null primary key, a.k varchar, b.k varchar) " + (disableWAL ? "DISABLE_WAL=true" : ""));
+ conn.createStatement().execute("UPSERT INTO t1 VALUES(1,'a','b')");
+ conn.createStatement().execute("DELETE FROM t1 WHERE k=2");
+ assertDurability(conn,expectedDurability);
+ conn.createStatement().execute("DELETE FROM t1 WHERE k=1");
+ assertDurability(conn,expectedDurability);
+ conn.createStatement().execute("DROP TABLE t1");
+ } finally {
+ conn.close();
+ }
+ }
+
+ private void assertDurability(Connection conn, Durability durability) throws SQLException {
+ PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
+ Iterator<Pair<byte[], List<Mutation>>> it = pconn.getMutationState().toMutations();
+ assertTrue(it.hasNext());
+ while (it.hasNext()) {
+ Pair<byte[], List<Mutation>> pair = it.next();
+ assertFalse(pair.getSecond().isEmpty());
+ for (Mutation m : pair.getSecond()) {
+ assertEquals(durability, m.getDurability());
+ }
+ }
+ }
+
+}