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

On StorageClient close, should also release meta client. #344

Merged
merged 3 commits into from
Sep 17, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

/**
* MetaManager is a manager for meta info, such as spaces,tags and edges.
* How to use:
* MetaManager manager = MetaManager.getMetaManager(Arrays.asList(HostAddress(host, port)));
*/
public class MetaManager implements MetaCache {
private class SpaceInfo {
Expand All @@ -45,43 +43,22 @@ private class SpaceInfo {

private static final Logger LOGGER = LoggerFactory.getLogger(MetaManager.class);

private static MetaClient metaClient;
private static MetaManager metaManager;
private MetaClient metaClient;
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

private MetaManager() {
}

/**
* init the meta info cache
* make sure this method is called before use metaManager
*/
private void init(List<HostAddress> address) throws TException {
public MetaManager(List<HostAddress> address) throws TException {
metaClient = new MetaClient(address);
metaClient.connect();
fillMetaInfo();
}

/**
* only way to get a MetaManager object
*/
public static MetaManager getMetaManager(List<HostAddress> address) throws TException {
if (metaManager == null) {
synchronized (MetaManager.class) {
if (metaManager == null) {
metaManager = new MetaManager();
metaManager.init(address);
}
}
}
return metaManager;
}

/**
* close meta client
*/
public void close() {
metaManager = null;
metaClient.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public boolean connect() throws Exception {
connection.open(addresses.get(0), timeout);
StoragePoolConfig config = new StoragePoolConfig();
pool = new StorageConnPool(config);
metaManager = MetaManager.getMetaManager(addresses);
metaManager = new MetaManager(addresses);
return true;
}

Expand Down Expand Up @@ -1069,6 +1069,9 @@ public void close() {
if (connection != null) {
connection.close();
}
if (metaManager != null) {
metaManager.close();
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TestMetaManager extends TestCase {

public void setUp() throws Exception {
MockNebulaGraph.initGraph();
metaManager = MetaManager.getMetaManager(
metaManager = new MetaManager(
Collections.singletonList(new HostAddress("127.0.0.1", 9559)));
}

Expand Down Expand Up @@ -100,7 +100,7 @@ public void testGetSpaceParts() {
public void testMultiVersionSchema() {
MockNebulaGraph.createMultiVersionTagAndEdge();
metaManager.close();
metaManager = MetaManager.getMetaManager(
metaManager = new MetaManager(
Collections.singletonList(new HostAddress("127.0.0.1", 9559)));
TagItem tagItem = metaManager.getTag("testMeta", "player");
assert (tagItem.getVersion() == 1);
Expand Down