Source:
public void testConcurrentDeletesAndUpsertValues() throws Exception { final String tableName = generateUniqueName(); final String indexName = generateUniqueName(); Connection conn = DriverManager.getConnection(getUrl()); conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 INTEGER NOT NULL, k2 INTEGER NOT NULL, v1 INTEGER, CONSTRAINT pk PRIMARY KEY (k1,k2))"); TestUtil.addCoprocessor(conn, tableName, DelayingRegionObserver.class); conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(v1)"); final CountDownLatch doneSignal = new CountDownLatch(2); Runnable r1 = new Runnable() { @Override public void run() { try { Connection conn = DriverManager.getConnection(getUrl()); conn.setAutoCommit(true); for (int i = 0; i < 50; i++) { Thread.sleep(20); conn.createStatement().execute("DELETE FROM " + tableName); } } catch (SQLException e) { throw new RuntimeException(e); } catch (InterruptedException e) { Thread.interrupted(); throw new RuntimeException(e); } finally { doneSignal.countDown(); } } }; Runnable r2 = new Runnable() { @Override public void run() { try { Connection conn = DriverManager.getConnection(getUrl()); for (int i = 0; i < 1000; i++) { conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES (" + (i % 10) + ", 0, 1)"); if ((i % 20) == 0) { conn.commit(); } } conn.commit(); } catch (SQLException e) { throw new RuntimeException(e); } finally { doneSignal.countDown(); } } }; Thread t1 = new Thread(r1); t1.start(); Thread t2 = new Thread(r2); t2.start(); doneSignal.await(60, TimeUnit.SECONDS); TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(tableName))); TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(indexName))); IndexScrutiny.scrutinizeIndex(conn, tableName, indexName); }

Target:
public void testConcurrentDeletesAndUpsertValues() throws Exception { final String tableName = generateUniqueName(); final String indexName = generateUniqueName(); Connection conn = DriverManager.getConnection(getUrl()); conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 INTEGER NOT NULL, k2 INTEGER NOT NULL, v1 INTEGER, CONSTRAINT pk PRIMARY KEY (k1,k2))"); TestUtil.addCoprocessor(conn, tableName, DelayingRegionObserver.class); conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(v1)"); final CountDownLatch doneSignal = new CountDownLatch(2); Runnable r1 = new Runnable() { @Override public void run() { try { Connection conn = DriverManager.getConnection(getUrl()); conn.setAutoCommit(true); for (int i = 0; i < 50; i++) { Thread.sleep(20); conn.createStatement().execute("DELETE FROM " + tableName); } } catch (SQLException e) { throw new RuntimeException(e); } catch (InterruptedException e) { Thread.interrupted(); throw new RuntimeException(e); } finally { doneSignal.countDown(); } } }; Runnable r2 = new Runnable() { @Override public void run() { try { Connection conn = DriverManager.getConnection(getUrl()); for (int i = 0; i < 1000; i++) { conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES (" + (i % 10) + ", 0, 1)"); if ((i % 20) == 0) { conn.commit(); } } conn.commit(); } catch (SQLException e) { throw new RuntimeException(e); } finally { doneSignal.countDown(); } } }; Thread t1 = new Thread(r1); t1.start(); Thread t2 = new Thread(r2); t2.start(); doneSignal.await(60, TimeUnit.SECONDS); IndexScrutiny.scrutinizeIndex(conn, tableName, indexName); }