You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2018/06/12 04:49:07 UTC
[22/23] phoenix git commit: Fix client-side local index deletes
Fix client-side local index deletes
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/5a1d1615
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/5a1d1615
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/5a1d1615
Branch: refs/heads/omid2
Commit: 5a1d161566ed5a1532ed24978a48ee9c32c8ece4
Parents: 629e487
Author: James Taylor <ja...@apache.org>
Authored: Sun Jun 3 00:09:46 2018 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Sun Jun 3 00:09:46 2018 -0700
----------------------------------------------------------------------
.../org/apache/phoenix/tx/TxCheckpointIT.java | 19 +++++++++++++------
.../apache/phoenix/execute/MutationState.java | 2 +-
.../apache/phoenix/schema/MetaDataClient.java | 2 +-
.../java/org/apache/phoenix/util/SchemaUtil.java | 10 +++++-----
4 files changed, 20 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a1d1615/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
index b438be9..cde3cf6 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
@@ -38,7 +38,6 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.transaction.PhoenixTransactionContext.PhoenixVisibilityLevel;
-import org.apache.phoenix.transaction.TransactionFactory;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.SchemaUtil;
import org.junit.Test;
@@ -133,7 +132,6 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
}
private void testRollbackOfUncommittedDelete(String indexDDL, String fullTableName) throws Exception {
- Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = getConnection();
conn.setAutoCommit(false);
try {
@@ -179,7 +177,15 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
assertEquals("a2", rs.getString(3));
assertFalse(rs.next());
- //assert row is delete in index table
+ // assert row is deleted in data table
+ rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName + " ORDER BY k");
+ assertTrue(rs.next());
+ assertEquals("x2", rs.getString(1));
+ assertEquals("y2", rs.getString(2));
+ assertEquals("a2", rs.getString(3));
+ assertFalse(rs.next());
+
+ // assert row is deleted in index table
rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName + " ORDER BY v1");
assertTrue(rs.next());
assertEquals("x2", rs.getString(1));
@@ -189,7 +195,7 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
conn.rollback();
- //assert two rows in data table
+ // assert two rows in data table
rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName + " ORDER BY k");
assertTrue(rs.next());
assertEquals("x1", rs.getString(1));
@@ -201,7 +207,7 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
assertEquals("a2", rs.getString(3));
assertFalse(rs.next());
- //assert two rows in index table
+ // assert two rows in index table
rs = stmt.executeQuery("select k, v1, v2 from " + fullTableName + " ORDER BY v1");
assertTrue(rs.next());
assertEquals("x1", rs.getString(1)); // fails here
@@ -330,7 +336,8 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
conn.commit();
MutationState state = conn.unwrap(PhoenixConnection.class).getMutationState();
- state.startTransaction(TransactionFactory.Provider.TEPHRA);
+ // Start a new transaction
+ stmt.executeQuery("select 1 from " + fullTableName + "1 LIMIT 1").next();
long wp = state.getWritePointer();
conn.createStatement().execute("delete from " + fullTableName + "1 where id1=fk1b AND fk1b=id1");
assertEquals(PhoenixVisibilityLevel.SNAPSHOT, state.getVisibilityLevel());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a1d1615/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
index 2f50626..c435c48 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
@@ -574,7 +574,7 @@ public class MutationState implements SQLCloseable {
MultiRowMutationState multiRowMutationState = mutations.remove(key);
if (multiRowMutationState!=null) {
final List<Mutation> deleteMutations = Lists.newArrayList();
- generateMutations(tableRef, mutationTimestamp, serverTimestamp, multiRowMutationState, deleteMutations, null);
+ generateMutations(key, mutationTimestamp, serverTimestamp, multiRowMutationState, deleteMutations, null);
if (indexMutations == null) {
indexMutations = deleteMutations;
} else {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a1d1615/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 7e9cfc9..76579a8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -3691,7 +3691,7 @@ public class MetaDataClient {
*/
private static byte[] getNewEmptyColumnFamilyOrNull (PTable table, PColumn columnToDrop) {
if (table.getType() != PTableType.VIEW && !SchemaUtil.isPKColumn(columnToDrop) && table.getColumnFamilies().get(0).getName().equals(columnToDrop.getFamilyName()) && table.getColumnFamilies().get(0).getColumns().size() == 1) {
- return SchemaUtil.getEmptyColumnFamily(table.getDefaultFamilyName(), table.getColumnFamilies().subList(1, table.getColumnFamilies().size()));
+ return SchemaUtil.getEmptyColumnFamily(table.getDefaultFamilyName(), table.getColumnFamilies().subList(1, table.getColumnFamilies().size()), table.getIndexType() == IndexType.LOCAL);
}
// If unchanged, return null
return null;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a1d1615/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
index dd00a69..a530816 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
@@ -496,23 +496,23 @@ public class SchemaUtil {
return isString ? ("'" + type.toObject(value).toString() + "'") : type.toObject(value, offset, length).toString();
}
- public static byte[] getEmptyColumnFamily(PName defaultColumnFamily, List<PColumnFamily> families) {
- return families.isEmpty() ? defaultColumnFamily == null ? QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES : defaultColumnFamily.getBytes() : families.get(0).getName().getBytes();
+ public static byte[] getEmptyColumnFamily(PName defaultColumnFamily, List<PColumnFamily> families, boolean isLocalIndex) {
+ return families.isEmpty() ? defaultColumnFamily == null ? (isLocalIndex ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES : QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES) : defaultColumnFamily.getBytes() : families.get(0).getName().getBytes();
}
public static byte[] getEmptyColumnFamily(PTable table) {
List<PColumnFamily> families = table.getColumnFamilies();
- return families.isEmpty() ? table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES : table.getDefaultFamilyName().getBytes() : families.get(0).getName().getBytes();
+ return families.isEmpty() ? table.getDefaultFamilyName() == null ? (table.getIndexType() == IndexType.LOCAL ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES : QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES) : table.getDefaultFamilyName().getBytes() : families.get(0).getName().getBytes();
}
public static String getEmptyColumnFamilyAsString(PTable table) {
List<PColumnFamily> families = table.getColumnFamilies();
- return families.isEmpty() ? table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY : table.getDefaultFamilyName().getString() : families.get(0).getName().getString();
+ return families.isEmpty() ? table.getDefaultFamilyName() == null ? (table.getIndexType() == IndexType.LOCAL ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY : QueryConstants.DEFAULT_COLUMN_FAMILY) : table.getDefaultFamilyName().getString() : families.get(0).getName().getString();
}
public static ImmutableBytesPtr getEmptyColumnFamilyPtr(PTable table) {
List<PColumnFamily> families = table.getColumnFamilies();
- return families.isEmpty() ? table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES_PTR : table.getDefaultFamilyName().getBytesPtr() : families.get(0)
+ return families.isEmpty() ? table.getDefaultFamilyName() == null ? (table.getIndexType() == IndexType.LOCAL ? QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES_PTR : QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES_PTR) : table.getDefaultFamilyName().getBytesPtr() : families.get(0)
.getName().getBytesPtr();
}