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

fix(pd-store): intro Useless annotation & refactor and mark the failed tests in hg-pd-test #2480

Merged
merged 18 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package org.apache.hugegraph.pd.client;

import org.apache.hugegraph.pd.common.Useless;
import org.apache.hugegraph.pd.grpc.discovery.NodeInfos;
import org.apache.hugegraph.pd.grpc.discovery.Query;

@Useless
public interface Discoverable {

NodeInfos getNodeInfos(Query query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.function.Function;

import org.apache.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.common.Useless;
import org.apache.hugegraph.pd.grpc.discovery.DiscoveryServiceGrpc;
import org.apache.hugegraph.pd.grpc.discovery.NodeInfo;
import org.apache.hugegraph.pd.grpc.discovery.NodeInfos;
Expand All @@ -38,6 +39,7 @@
import io.grpc.ManagedChannelBuilder;
import lombok.extern.slf4j.Slf4j;

@Useless
@Slf4j
public abstract class DiscoveryClient implements Closeable, Discoverable {

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

import org.apache.hugegraph.pd.common.Useless;
import org.apache.hugegraph.pd.grpc.discovery.NodeInfo;
import org.apache.hugegraph.pd.grpc.discovery.RegisterType;

@Useless
public class DiscoveryClientImpl extends DiscoveryClient {

private final String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hugegraph.pd.client;

import org.apache.hugegraph.pd.common.KVPair;
import org.apache.hugegraph.pd.common.Useless;
import org.apache.hugegraph.pd.grpc.PDGrpc;
import org.apache.hugegraph.pd.grpc.Pdpb;

Expand All @@ -27,6 +28,7 @@
import io.grpc.stub.AbstractStub;
import lombok.extern.slf4j.Slf4j;

@Useless
@Slf4j
public class LicenseClient extends AbstractClient {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.apache.hugegraph.pd.common;
VGalaxies marked this conversation as resolved.
Show resolved Hide resolved

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* The "Useless" annotation indicates that the annotated object can be safely removed without
* affecting existing functionality, including objects that are only referenced in tests.
*/
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
public @interface Useless {}
VGalaxies marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hugegraph.pd;

import java.util.List;
import java.util.Objects;

import org.apache.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.config.PDConfig;
Expand Down Expand Up @@ -128,7 +129,11 @@ public synchronized PDConfig setPartitionCount(int count) {
* @throws PDException when io error
*/
public int getPartitionCount() throws PDException {
return getPDConfig().getPartitionCount();
Metapb.PDConfig config = getPDConfig();
if (Objects.nonNull(config)) {
return config.getPartitionCount();
}
return pdConfig.getInitialPartitionCount();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public void shutDown() {
}

public boolean isLeader() {
if (Objects.isNull(this.raftNode)) {
return false;
}
return this.raftNode.isLeader(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@

import org.apache.hugegraph.pd.common.KVPair;
import org.apache.hugegraph.pd.common.PartitionCache;
import org.apache.hugegraph.pd.common.Useless;
import org.apache.hugegraph.pd.grpc.Metapb;

import com.google.common.collect.Range;
import com.google.common.collect.RangeMap;
import com.google.common.collect.TreeRangeMap;

@Useless
public class PartitionCacheTest {

// @Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import java.util.Collections;
import java.util.List;

import org.apache.hugegraph.pd.common.Useless;
import org.apache.hugegraph.pd.grpc.Metapb;
import org.junit.Test;

@Useless
public class PartitionServiceTest {
@Test
public void testPartitionHeartbeat() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import java.io.File;

import org.apache.hugegraph.pd.common.Useless;

@Useless
public class UnitTestBase {
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
* limitations under the License.
*/

package org.apache.hugegraph.pd;
package org.apache.hugegraph.pd.client;

import java.nio.charset.StandardCharsets;
import java.util.List;

import org.apache.hugegraph.pd.client.PDClient;
import org.apache.hugegraph.pd.client.PDConfig;
import org.apache.hugegraph.pd.client.PDPulse;
import org.apache.hugegraph.pd.client.PDPulseImpl;
import org.apache.hugegraph.pd.common.KVPair;
import org.apache.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.grpc.Metapb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
* limitations under the License.
*/

package org.apache.hugegraph.pd;
package org.apache.hugegraph.pd.service;

import java.util.concurrent.ExecutionException;

import org.apache.hugegraph.pd.PartitionService;
import org.apache.hugegraph.pd.StoreNodeService;
import org.apache.hugegraph.pd.TaskScheduleService;
import org.apache.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.config.PDConfig;
import org.apache.hugegraph.pd.grpc.Metapb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.hugegraph.pd;
package org.apache.hugegraph.pd.service;

import java.io.File;
import java.io.IOException;
Expand All @@ -25,6 +25,11 @@
import java.util.concurrent.atomic.AtomicReference;

import org.apache.commons.io.FileUtils;
import org.apache.hugegraph.pd.ConfigService;
import org.apache.hugegraph.pd.PartitionInstructionListener;
import org.apache.hugegraph.pd.PartitionService;
import org.apache.hugegraph.pd.PartitionStatusListener;
import org.apache.hugegraph.pd.StoreNodeService;
import org.apache.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.config.PDConfig;
import org.apache.hugegraph.pd.grpc.Metapb;
Expand Down
Loading