Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTERNAL: Remove duplicated pipe max item count vars. #871

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 21 additions & 28 deletions src/main/java/net/spy/memcached/ArcusClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public class ArcusClient extends FrontCacheMemcachedClient implements ArcusClien
private static final Logger arcusLogger = LoggerFactory.getLogger(ArcusClient.class);
private static final String ARCUS_ADMIN_ADDR = "127.0.0.1:2181";
private static final String DEFAULT_ARCUS_CLIENT_NAME = "ArcusClient";
public static final int MAX_PIPED_ITEM_COUNT = 500;

private final Transcoder<Object> collectionTranscoder;

Expand Down Expand Up @@ -844,10 +845,10 @@ public void complete() {
// got status
public void gotStatus(Integer index, OperationStatus status) {
if (status instanceof CollectionOperationStatus) {
rv.addEachResult(index + (idx * CollectionPipedUpdate.MAX_PIPED_ITEM_COUNT),
rv.addEachResult(index + (idx * MAX_PIPED_ITEM_COUNT),
(CollectionOperationStatus) status);
} else {
rv.addEachResult(index + (idx * CollectionPipedUpdate.MAX_PIPED_ITEM_COUNT),
rv.addEachResult(index + (idx * MAX_PIPED_ITEM_COUNT),
new CollectionOperationStatus(status));
}
}
Expand Down Expand Up @@ -1774,11 +1775,10 @@ public <T> CollectionFuture<Map<Integer, CollectionOperationStatus>> asyncBopPip

List<CollectionPipedInsert<T>> insertList = new ArrayList<>();

if (elements.size() <= CollectionPipedInsert.MAX_PIPED_ITEM_COUNT) {
if (elements.size() <= MAX_PIPED_ITEM_COUNT) {
insertList.add(new BTreePipedInsert<>(key, elements, attributesForCreate, tc));
} else {
PartitionedMap<Long, T> list = new PartitionedMap<>(
elements, CollectionPipedInsert.MAX_PIPED_ITEM_COUNT);
PartitionedMap<Long, T> list = new PartitionedMap<>(elements, MAX_PIPED_ITEM_COUNT);
for (Map<Long, T> elementMap : list) {
insertList.add(new BTreePipedInsert<>(key, elementMap, attributesForCreate, tc));
}
Expand All @@ -1798,11 +1798,10 @@ public <T> CollectionFuture<Map<Integer, CollectionOperationStatus>> asyncBopPip

List<CollectionPipedInsert<T>> insertList = new ArrayList<>();

if (elements.size() <= CollectionPipedInsert.MAX_PIPED_ITEM_COUNT) {
if (elements.size() <= MAX_PIPED_ITEM_COUNT) {
insertList.add(new ByteArraysBTreePipedInsert<>(key, elements, attributesForCreate, tc));
} else {
PartitionedList<Element<T>> list = new PartitionedList<>(
elements, CollectionPipedInsert.MAX_PIPED_ITEM_COUNT);
PartitionedList<Element<T>> list = new PartitionedList<>(elements, MAX_PIPED_ITEM_COUNT);
for (List<Element<T>> elementList : list) {
insertList.add(new ByteArraysBTreePipedInsert<>(key, elementList, attributesForCreate, tc));
}
Expand All @@ -1826,11 +1825,10 @@ public <T> CollectionFuture<Map<Integer, CollectionOperationStatus>> asyncMopPip

List<CollectionPipedInsert<T>> insertList = new ArrayList<>();

if (elements.size() <= CollectionPipedInsert.MAX_PIPED_ITEM_COUNT) {
if (elements.size() <= MAX_PIPED_ITEM_COUNT) {
insertList.add(new MapPipedInsert<>(key, elements, attributesForCreate, tc));
} else {
PartitionedMap<String, T> list = new PartitionedMap<>(
elements, CollectionPipedInsert.MAX_PIPED_ITEM_COUNT);
PartitionedMap<String, T> list = new PartitionedMap<>(elements, MAX_PIPED_ITEM_COUNT);
for (Map<String, T> elementMap : list) {
insertList.add(new MapPipedInsert<>(key, elementMap, attributesForCreate, tc));
}
Expand All @@ -1850,11 +1848,10 @@ public <T> CollectionFuture<Map<Integer, CollectionOperationStatus>> asyncLopPip

List<CollectionPipedInsert<T>> insertList = new ArrayList<>();

if (valueList.size() <= CollectionPipedInsert.MAX_PIPED_ITEM_COUNT) {
if (valueList.size() <= MAX_PIPED_ITEM_COUNT) {
insertList.add(new ListPipedInsert<>(key, index, valueList, attributesForCreate, tc));
} else {
PartitionedList<T> list = new PartitionedList<>(valueList,
CollectionPipedInsert.MAX_PIPED_ITEM_COUNT);
PartitionedList<T> list = new PartitionedList<>(valueList, MAX_PIPED_ITEM_COUNT);
for (List<T> elementList : list) {
insertList.add(new ListPipedInsert<>(key, index, elementList, attributesForCreate, tc));
}
Expand All @@ -1874,11 +1871,10 @@ public <T> CollectionFuture<Map<Integer, CollectionOperationStatus>> asyncSopPip

List<CollectionPipedInsert<T>> insertList = new ArrayList<>();

if (valueList.size() <= CollectionPipedInsert.MAX_PIPED_ITEM_COUNT) {
if (valueList.size() <= MAX_PIPED_ITEM_COUNT) {
insertList.add(new SetPipedInsert<>(key, valueList, attributesForCreate, tc));
} else {
PartitionedList<T> list = new PartitionedList<>(valueList,
CollectionPipedInsert.MAX_PIPED_ITEM_COUNT);
PartitionedList<T> list = new PartitionedList<>(valueList, MAX_PIPED_ITEM_COUNT);
for (List<T> elementList : list) {
insertList.add(new SetPipedInsert<>(key, elementList, attributesForCreate, tc));
}
Expand Down Expand Up @@ -2310,11 +2306,10 @@ public <T> CollectionFuture<Map<Integer, CollectionOperationStatus>> asyncBopPip

List<CollectionPipedUpdate<T>> updateList = new ArrayList<>();

if (elements.size() <= CollectionPipedUpdate.MAX_PIPED_ITEM_COUNT) {
if (elements.size() <= MAX_PIPED_ITEM_COUNT) {
updateList.add(new BTreePipedUpdate<>(key, elements, tc));
} else {
PartitionedList<Element<T>> list = new PartitionedList<>(
elements, CollectionPipedUpdate.MAX_PIPED_ITEM_COUNT);
PartitionedList<Element<T>> list = new PartitionedList<>(elements, MAX_PIPED_ITEM_COUNT);
for (List<Element<T>> elementList : list) {
updateList.add(new BTreePipedUpdate<>(key, elementList, tc));
}
Expand Down Expand Up @@ -2343,12 +2338,10 @@ public <T> CollectionFuture<Map<Integer, CollectionOperationStatus>> asyncMopPip

List<CollectionPipedUpdate<T>> updateList = new ArrayList<>();

if (elements.size() <= CollectionPipedUpdate.MAX_PIPED_ITEM_COUNT) {
if (elements.size() <= MAX_PIPED_ITEM_COUNT) {
updateList.add(new MapPipedUpdate<>(key, elements, tc));
} else {
PartitionedMap<String, T> list = new PartitionedMap<>(
elements, CollectionPipedUpdate.MAX_PIPED_ITEM_COUNT);

PartitionedMap<String, T> list = new PartitionedMap<>(elements, MAX_PIPED_ITEM_COUNT);
for (Map<String, T> elementMap : list) {
updateList.add(new MapPipedUpdate<>(key, elementMap, tc));
}
Expand Down Expand Up @@ -2943,10 +2936,10 @@ <T> CollectionFuture<Map<T, Boolean>> asyncSetPipedExist(
throw new IllegalArgumentException(
"The number of piped operations must be larger than 0.");
}
if (exist.getItemCount() > SetPipedExist.MAX_PIPED_ITEM_COUNT) {
if (exist.getItemCount() > MAX_PIPED_ITEM_COUNT) {
throw new IllegalArgumentException(
"The number of piped operations must not exceed a maximum of "
+ SetPipedExist.MAX_PIPED_ITEM_COUNT + ".");
+ MAX_PIPED_ITEM_COUNT + ".");
}

final CountDownLatch latch = new CountDownLatch(1);
Expand Down Expand Up @@ -3107,10 +3100,10 @@ public void complete() {
// got status
public void gotStatus(Integer index, OperationStatus status) {
if (status instanceof CollectionOperationStatus) {
rv.addEachResult(index + (idx * CollectionPipedInsert.MAX_PIPED_ITEM_COUNT),
rv.addEachResult(index + (idx * MAX_PIPED_ITEM_COUNT),
(CollectionOperationStatus) status);
} else {
rv.addEachResult(index + (idx * CollectionPipedInsert.MAX_PIPED_ITEM_COUNT),
rv.addEachResult(index + (idx * MAX_PIPED_ITEM_COUNT),
new CollectionOperationStatus(status));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

public abstract class CollectionPipedInsert<T> extends CollectionPipe {

public static final int MAX_PIPED_ITEM_COUNT = 500;

protected final String key;
protected final CollectionAttributes attribute;
protected final Transcoder<T> tc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

public abstract class CollectionPipedUpdate<T> extends CollectionPipe {

public static final int MAX_PIPED_ITEM_COUNT = 500;

protected final String key;
protected final Transcoder<T> tc;

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/spy/memcached/collection/SetPipedExist.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

public class SetPipedExist<T> extends CollectionPipe {

public static final int MAX_PIPED_ITEM_COUNT = 500;

private static final String COMMAND = "sop exist";

private final String key;
Expand Down
7 changes: 3 additions & 4 deletions src/test/java/net/spy/memcached/ArcusTimeoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.concurrent.TimeoutException;

import net.spy.memcached.collection.CollectionAttributes;
import net.spy.memcached.collection.CollectionPipedInsert;
import net.spy.memcached.collection.ElementFlagFilter;
import net.spy.memcached.collection.SMGetElement;
import net.spy.memcached.collection.SMGetMode;
Expand Down Expand Up @@ -142,7 +141,7 @@ void testBulkDeleteTimeoutUsingSingleThread() {
@Test
void testSopPipedInsertBulkTimeout() {
String key = "testTimeout";
int valueCount = CollectionPipedInsert.MAX_PIPED_ITEM_COUNT;
int valueCount = ArcusClient.MAX_PIPED_ITEM_COUNT;
Object[] valueList = new Object[valueCount];
for (int i = 0; i < valueList.length; i++) {
valueList[i] = "MyValue" + i;
Expand Down Expand Up @@ -199,7 +198,7 @@ void testBopPipedInsertBulkTimeout() {
String key = "MyBopKey";
String value = "MyValue";

int bkeySize = CollectionPipedInsert.MAX_PIPED_ITEM_COUNT;
int bkeySize = ArcusClient.MAX_PIPED_ITEM_COUNT;
Map<Long, Object> bkeys = new TreeMap<>();
for (int i = 0; i < bkeySize; i++) {
bkeys.put((long) i, value);
Expand Down Expand Up @@ -297,7 +296,7 @@ void testMopInsertBulkMultipleTimeout() {
String key = "MyMopKey";
String value = "MyValue";

int elementSize = CollectionPipedInsert.MAX_PIPED_ITEM_COUNT;
int elementSize = ArcusClient.MAX_PIPED_ITEM_COUNT;
Map<String, Object> elements = new TreeMap<>();
for (int i = 0; i < elementSize; i++) {
elements.put(String.valueOf(i), value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import net.spy.memcached.ArcusClient;
import net.spy.memcached.collection.BaseIntegrationTest;
import net.spy.memcached.collection.CollectionAttributes;
import net.spy.memcached.collection.CollectionPipedInsert;
import net.spy.memcached.ops.CollectionOperationStatus;

import org.junit.jupiter.api.Test;
Expand All @@ -42,7 +42,7 @@ void testInsertAndGet() {
String key = "testInsertAndGet";
String prefix = "MyValue";

int valueCount = CollectionPipedInsert.MAX_PIPED_ITEM_COUNT;
int valueCount = ArcusClient.MAX_PIPED_ITEM_COUNT;
Object[] valueList = new Object[valueCount];
for (int i = 0; i < valueList.length; i++) {
valueList[i] = String.format("%s%d", prefix, i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import net.spy.memcached.ArcusClient;
import net.spy.memcached.collection.BaseIntegrationTest;
import net.spy.memcached.collection.CollectionAttributes;
import net.spy.memcached.collection.CollectionOverflowAction;
import net.spy.memcached.collection.CollectionPipedInsert;
import net.spy.memcached.internal.CollectionFuture;
import net.spy.memcached.ops.CollectionOperationStatus;

Expand All @@ -43,7 +43,7 @@ class LopBulkAPITest extends BaseIntegrationTest {
private final List<Object> valueList = new ArrayList<>();

private int getValueCount() {
return CollectionPipedInsert.MAX_PIPED_ITEM_COUNT;
return ArcusClient.MAX_PIPED_ITEM_COUNT;
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import net.spy.memcached.ArcusClient;
import net.spy.memcached.collection.BaseIntegrationTest;
import net.spy.memcached.collection.CollectionAttributes;
import net.spy.memcached.collection.CollectionOverflowAction;
import net.spy.memcached.collection.CollectionPipedInsert;
import net.spy.memcached.internal.CollectionFuture;
import net.spy.memcached.ops.CollectionOperationStatus;

Expand All @@ -42,7 +42,7 @@ class MopBulkAPITest extends BaseIntegrationTest {
private final Map<String, Object> updateMap = new HashMap<>();

private int getValueCount() {
return CollectionPipedInsert.MAX_PIPED_ITEM_COUNT;
return ArcusClient.MAX_PIPED_ITEM_COUNT;
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import net.spy.memcached.ArcusClient;
import net.spy.memcached.collection.BaseIntegrationTest;
import net.spy.memcached.collection.CollectionAttributes;
import net.spy.memcached.collection.CollectionPipedInsert;
import net.spy.memcached.internal.CollectionFuture;
import net.spy.memcached.ops.CollectionOperationStatus;

Expand All @@ -43,7 +43,7 @@ class SopBulkAPITest extends BaseIntegrationTest {
private final List<Object> valueList = new ArrayList<>();

private int getValueCount() {
return CollectionPipedInsert.MAX_PIPED_ITEM_COUNT;
return ArcusClient.MAX_PIPED_ITEM_COUNT;
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import java.util.List;
import java.util.Map;

import net.spy.memcached.ArcusClient;
import net.spy.memcached.collection.BaseIntegrationTest;
import net.spy.memcached.collection.CollectionAttributes;
import net.spy.memcached.collection.CollectionResponse;
import net.spy.memcached.collection.ElementValueType;
import net.spy.memcached.collection.SetPipedExist;
import net.spy.memcached.internal.CollectionFuture;

import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -146,7 +146,7 @@ void testMaxPipedExist() {
List<Object> findValues = new ArrayList<>();

// insert items
for (int i = 0; i < SetPipedExist.MAX_PIPED_ITEM_COUNT; i++) {
for (int i = 0; i < ArcusClient.MAX_PIPED_ITEM_COUNT; i++) {
findValues.add("VALUE" + i);

if (i / 2 == 0) {
Expand All @@ -164,7 +164,7 @@ void testMaxPipedExist() {

assertTrue(future.getOperationStatus().isSuccess());

for (int i = 0; i < SetPipedExist.MAX_PIPED_ITEM_COUNT; i++) {
for (int i = 0; i < ArcusClient.MAX_PIPED_ITEM_COUNT; i++) {
if (i / 2 == 0) {
assertFalse(map.get("VALUE" + i));
} else {
Expand Down