HBASE-20485 Copy constructor of Scan doesn't copy the readType and replicaId
Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
parent
421ed6ca51
commit
55badefa38
|
@ -279,6 +279,8 @@ public class Scan extends Query {
|
||||||
this.limit = scan.getLimit();
|
this.limit = scan.getLimit();
|
||||||
this.needCursorResult = scan.isNeedCursorResult();
|
this.needCursorResult = scan.isNeedCursorResult();
|
||||||
setPriority(scan.getPriority());
|
setPriority(scan.getPriority());
|
||||||
|
readType = scan.getReadType();
|
||||||
|
super.setReplicaId(scan.getReplicaId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -310,6 +312,7 @@ public class Scan extends Query {
|
||||||
}
|
}
|
||||||
this.mvccReadPoint = -1L;
|
this.mvccReadPoint = -1L;
|
||||||
setPriority(get.getPriority());
|
setPriority(get.getPriority());
|
||||||
|
super.setReplicaId(get.getReplicaId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGetScan() {
|
public boolean isGetScan() {
|
||||||
|
|
|
@ -24,9 +24,13 @@ import static org.junit.Assert.fail;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||||
import org.apache.hadoop.hbase.HConstants;
|
import org.apache.hadoop.hbase.HConstants;
|
||||||
|
import org.apache.hadoop.hbase.client.Scan.ReadType;
|
||||||
import org.apache.hadoop.hbase.filter.FilterList;
|
import org.apache.hadoop.hbase.filter.FilterList;
|
||||||
|
import org.apache.hadoop.hbase.security.access.Permission;
|
||||||
import org.apache.hadoop.hbase.security.visibility.Authorizations;
|
import org.apache.hadoop.hbase.security.visibility.Authorizations;
|
||||||
import org.apache.hadoop.hbase.testclassification.ClientTests;
|
import org.apache.hadoop.hbase.testclassification.ClientTests;
|
||||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||||
|
@ -35,7 +39,6 @@ import org.junit.Assert;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos;
|
||||||
|
|
||||||
|
@ -66,7 +69,7 @@ public class TestScan {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetToScan() throws IOException {
|
public void testGetToScan() throws Exception {
|
||||||
Get get = new Get(Bytes.toBytes(1));
|
Get get = new Get(Bytes.toBytes(1));
|
||||||
get.setCacheBlocks(true)
|
get.setCacheBlocks(true)
|
||||||
.setConsistency(Consistency.TIMELINE)
|
.setConsistency(Consistency.TIMELINE)
|
||||||
|
@ -79,7 +82,12 @@ public class TestScan {
|
||||||
.setRowOffsetPerColumnFamily(5)
|
.setRowOffsetPerColumnFamily(5)
|
||||||
.setTimeRange(0, 13)
|
.setTimeRange(0, 13)
|
||||||
.setAttribute("att_v0", Bytes.toBytes("att_v0"))
|
.setAttribute("att_v0", Bytes.toBytes("att_v0"))
|
||||||
.setColumnFamilyTimeRange(Bytes.toBytes("cf"), 0, 123);
|
.setColumnFamilyTimeRange(Bytes.toBytes("cf"), 0, 123)
|
||||||
|
.setReplicaId(3)
|
||||||
|
.setACL("test_user", new Permission(Permission.Action.READ))
|
||||||
|
.setAuthorizations(new Authorizations("test_label"))
|
||||||
|
.setPriority(3);
|
||||||
|
|
||||||
Scan scan = new Scan(get);
|
Scan scan = new Scan(get);
|
||||||
assertEquals(get.getCacheBlocks(), scan.getCacheBlocks());
|
assertEquals(get.getCacheBlocks(), scan.getCacheBlocks());
|
||||||
assertEquals(get.getConsistency(), scan.getConsistency());
|
assertEquals(get.getConsistency(), scan.getConsistency());
|
||||||
|
@ -97,6 +105,10 @@ public class TestScan {
|
||||||
scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin());
|
scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin());
|
||||||
assertEquals(get.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMax(),
|
assertEquals(get.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMax(),
|
||||||
scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMax());
|
scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMax());
|
||||||
|
assertEquals(get.getReplicaId(), scan.getReplicaId());
|
||||||
|
assertEquals(get.getACL(), scan.getACL());
|
||||||
|
assertEquals(get.getAuthorizations().getLabels(), scan.getAuthorizations().getLabels());
|
||||||
|
assertEquals(get.getPriority(), scan.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -201,5 +213,81 @@ public class TestScan {
|
||||||
fail("expected IllegalArgumentException to be thrown");
|
fail("expected IllegalArgumentException to be thrown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testScanCopyConstructor() throws Exception {
|
||||||
|
Scan scan = new Scan();
|
||||||
|
|
||||||
|
scan.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("q"))
|
||||||
|
.setACL("test_user", new Permission(Permission.Action.READ))
|
||||||
|
.setAllowPartialResults(true)
|
||||||
|
.setAsyncPrefetch(false)
|
||||||
|
.setAttribute("test_key", Bytes.toBytes("test_value"))
|
||||||
|
.setAuthorizations(new Authorizations("test_label"))
|
||||||
|
.setBatch(10)
|
||||||
|
.setCacheBlocks(false)
|
||||||
|
.setCaching(10)
|
||||||
|
.setConsistency(Consistency.TIMELINE)
|
||||||
|
.setFilter(new FilterList())
|
||||||
|
.setId("scan_copy_constructor")
|
||||||
|
.setIsolationLevel(IsolationLevel.READ_COMMITTED)
|
||||||
|
.setLimit(100)
|
||||||
|
.setLoadColumnFamiliesOnDemand(false)
|
||||||
|
.setMaxResultSize(100)
|
||||||
|
.setMaxResultsPerColumnFamily(1000)
|
||||||
|
.readVersions(9999)
|
||||||
|
.setMvccReadPoint(5)
|
||||||
|
.setNeedCursorResult(true)
|
||||||
|
.setPriority(1)
|
||||||
|
.setRaw(true)
|
||||||
|
.setReplicaId(3)
|
||||||
|
.setReversed(true)
|
||||||
|
.setRowOffsetPerColumnFamily(5)
|
||||||
|
.setRowPrefixFilter(Bytes.toBytes("row_"))
|
||||||
|
.setScanMetricsEnabled(true)
|
||||||
|
.setSmall(true)
|
||||||
|
.setReadType(ReadType.STREAM)
|
||||||
|
.withStartRow(Bytes.toBytes("row_1"))
|
||||||
|
.withStopRow(Bytes.toBytes("row_2"))
|
||||||
|
.setTimeRange(0, 13);
|
||||||
|
|
||||||
|
// create a copy of existing scan object
|
||||||
|
Scan scanCopy = new Scan(scan);
|
||||||
|
|
||||||
|
// validate fields of copied scan object match with the original scan object
|
||||||
|
assertEquals(scan.getACL(), scanCopy.getACL());
|
||||||
|
assertEquals(scan.getAllowPartialResults(), scanCopy.getAllowPartialResults());
|
||||||
|
assertEquals(scan.getAttribute("test_key"), scanCopy.getAttribute("test_key"));
|
||||||
|
assertEquals(scan.getAttributeSize(), scanCopy.getAttributeSize());
|
||||||
|
assertEquals(scan.getAttributesMap(), scanCopy.getAttributesMap());
|
||||||
|
assertEquals(scan.getAuthorizations().getLabels(), scanCopy.getAuthorizations().getLabels());
|
||||||
|
assertEquals(scan.getBatch(), scanCopy.getBatch());
|
||||||
|
assertEquals(scan.getCacheBlocks(), scanCopy.getCacheBlocks());
|
||||||
|
assertEquals(scan.getCaching(), scanCopy.getCaching());
|
||||||
|
assertEquals(scan.getConsistency(), scanCopy.getConsistency());
|
||||||
|
assertEquals(scan.getFamilies().length, scanCopy.getFamilies().length);
|
||||||
|
assertEquals(scan.getFamilies()[0], scanCopy.getFamilies()[0]);
|
||||||
|
assertEquals(scan.getFamilyMap(), scanCopy.getFamilyMap());
|
||||||
|
assertEquals(scan.getFilter(), scanCopy.getFilter());
|
||||||
|
assertEquals(scan.getId(), scanCopy.getId());
|
||||||
|
assertEquals(scan.getIsolationLevel(), scanCopy.getIsolationLevel());
|
||||||
|
assertEquals(scan.getLimit(), scanCopy.getLimit());
|
||||||
|
assertEquals(scan.getLoadColumnFamiliesOnDemandValue(),
|
||||||
|
scanCopy.getLoadColumnFamiliesOnDemandValue());
|
||||||
|
assertEquals(scan.getMaxResultSize(), scanCopy.getMaxResultSize());
|
||||||
|
assertEquals(scan.getMaxResultsPerColumnFamily(), scanCopy.getMaxResultsPerColumnFamily());
|
||||||
|
assertEquals(scan.getMaxVersions(), scanCopy.getMaxVersions());
|
||||||
|
assertEquals(scan.getMvccReadPoint(), scanCopy.getMvccReadPoint());
|
||||||
|
assertEquals(scan.getPriority(), scanCopy.getPriority());
|
||||||
|
assertEquals(scan.getReadType(), scanCopy.getReadType());
|
||||||
|
assertEquals(scan.getReplicaId(), scanCopy.getReplicaId());
|
||||||
|
assertEquals(scan.getRowOffsetPerColumnFamily(), scanCopy.getRowOffsetPerColumnFamily());
|
||||||
|
assertEquals(scan.getStartRow(), scanCopy.getStartRow());
|
||||||
|
assertEquals(scan.getStopRow(), scanCopy.getStopRow());
|
||||||
|
assertEquals(scan.getTimeRange(), scanCopy.getTimeRange());
|
||||||
|
|
||||||
|
assertTrue("Make sure copy constructor adds all the fields in the copied object",
|
||||||
|
EqualsBuilder.reflectionEquals(scan, scanCopy));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ import org.apache.zookeeper.KeeperException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks the switch of split and merge states in ZK
|
* Tracks the switch of split and merge states in ZK
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class SplitOrMergeTracker {
|
public class SplitOrMergeTracker {
|
||||||
|
|
Loading…
Reference in New Issue