Skip to content

Commit

Permalink
removed not needed information from open response
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed May 23, 2017
1 parent 045468f commit 11995eb
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 16 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.orientechnologies.orient.core.command.OCommandRequestText; import com.orientechnologies.orient.core.command.OCommandRequestText;
import com.orientechnologies.orient.core.config.OContextConfiguration; import com.orientechnologies.orient.core.config.OContextConfiguration;
import com.orientechnologies.orient.core.config.OGlobalConfiguration; import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.config.OStorageClusterConfiguration;
import com.orientechnologies.orient.core.config.OStorageConfiguration; import com.orientechnologies.orient.core.config.OStorageConfiguration;
import com.orientechnologies.orient.core.conflict.ORecordConflictStrategy; import com.orientechnologies.orient.core.conflict.ORecordConflictStrategy;
import com.orientechnologies.orient.core.db.ODatabase; import com.orientechnologies.orient.core.db.ODatabase;
Expand Down Expand Up @@ -397,7 +398,7 @@ public void open(final String iUserName, final String iUserPassword, final OCont
ORecordSerializerFactory.instance().getDefaultRecordSerializer().toString()); ORecordSerializerFactory.instance().getDefaultRecordSerializer().toString());
storageConfiguration.load(conf); storageConfiguration.load(conf);


configuration = storageConfiguration; updateStorageConfiguration(storageConfiguration);


componentsFactory = new OCurrentStorageComponentsFactory(configuration); componentsFactory = new OCurrentStorageComponentsFactory(configuration);


Expand All @@ -423,11 +424,16 @@ public OSBTreeCollectionManager getSBtreeCollectionManager() {
} }


public void reload() { public void reload() {
final OStorageConfiguration storageConfiguration = new OStorageRemoteConfiguration(this,
ORecordSerializerFactory.instance().getDefaultRecordSerializer().toString());
storageConfiguration.load(clientConfiguration);


OReloadRequest request = new OReloadRequest(); updateStorageConfiguration(storageConfiguration);
OReloadResponse response = networkOperation(request, "Error on reloading database information"); //

// OReloadRequest request = new OReloadRequest();
updateStorageInformations(response.getClusters()); // OReloadResponse response = networkOperation(request, "Error on reloading database information");
//
// updateStorageInformations(response.getClusters());
} }


public void create(OContextConfiguration contextConfiguration) { public void create(OContextConfiguration contextConfiguration) {
Expand Down Expand Up @@ -1277,7 +1283,7 @@ public void openRemoteDatabase(OChannelBinaryAsynchClient network) throws IOExce
endRequest(network); endRequest(network);
} }
final int sessionId; final int sessionId;
OOpenResponse response = request.createResponse(); OOpenResponse37 response = request.createResponse();
try { try {
network.beginResponse(nodeSession.getSessionId(), false); network.beginResponse(nodeSession.getSessionId(), false);
response.read(network, session); response.read(network, session);
Expand All @@ -1295,11 +1301,11 @@ public void openRemoteDatabase(OChannelBinaryAsynchClient network) throws IOExce


OLogManager.instance().debug(this, "Client connected to %s with session id=%d", network.getServerURL(), sessionId); OLogManager.instance().debug(this, "Client connected to %s with session id=%d", network.getServerURL(), sessionId);


OCluster[] cl = response.getClusterIds(); // OCluster[] cl = response.getClusterIds();
updateStorageInformations(cl); // updateStorageInformations(cl);


// READ CLUSTER CONFIGURATION // READ CLUSTER CONFIGURATION
updateClusterConfiguration(network.getServerURL(), response.getDistributedConfiguration()); // updateClusterConfiguration(network.getServerURL(), response.getDistributedConfiguration());


// This need to be protected by a lock for now, let's see in future // This need to be protected by a lock for now, let's see in future
stateLock.acquireWriteLock(); stateLock.acquireWriteLock();
Expand Down Expand Up @@ -1344,7 +1350,6 @@ protected void openRemoteDatabase(String currentURL) {
OChannelBinaryAsynchClient network = null; OChannelBinaryAsynchClient network = null;
try { try {
network = getNetwork(currentURL); network = getNetwork(currentURL);
final int serverVersion = network.getSrvProtocolVersion();
openRemoteDatabase(network); openRemoteDatabase(network);
return; return;
} catch (OIOException e) { } catch (OIOException e) {
Expand Down Expand Up @@ -1652,8 +1657,24 @@ private boolean handleDBFreeze() {
return retry; return retry;
} }


public void updateStorageInformations(OCluster[] clusters) { public void updateStorageConfiguration(OStorageConfiguration storageConfiguration) {
stateLock.acquireWriteLock(); stateLock.acquireWriteLock();
this.configuration = storageConfiguration;
OCluster[] clusters = new OCluster[storageConfiguration.clusters.size()];
for (OStorageClusterConfiguration clusterConfig : storageConfiguration.clusters) {
if (clusterConfig != null) {
final OClusterRemote cluster = new OClusterRemote();
String clusterName = clusterConfig.getName();
final int clusterId = clusterConfig.getId();
if (clusterName != null) {
clusterName = clusterName.toLowerCase();
cluster.configure(null, clusterId, clusterName);
if (clusterId >= clusters.length)
clusters = Arrays.copyOf(clusters, clusterId + 1);
clusters[clusterId] = cluster;
}
}
}
try { try {
this.clusters = clusters; this.clusters = clusters;
clusterMap.clear(); clusterMap.clear();
Expand All @@ -1669,6 +1690,23 @@ public void updateStorageInformations(OCluster[] clusters) {
} }
} }


public void updateStorageInformations(OCluster[] clusters) {
// stateLock.acquireWriteLock();
// try {
// this.clusters = clusters;
// clusterMap.clear();
// for (int i = 0; i < clusters.length; ++i) {
// if (clusters[i] != null)
// clusterMap.put(clusters[i].getName(), clusters[i]);
// }
// final OCluster defaultCluster = clusterMap.get(CLUSTER_DEFAULT_NAME);
// if (defaultCluster != null)
// defaultClusterId = clusterMap.get(CLUSTER_DEFAULT_NAME).getId();
// } finally {
// stateLock.releaseWriteLock();
// }
}

protected OStorageRemoteSession getCurrentSession() { protected OStorageRemoteSession getCurrentSession() {
ODatabaseDocumentInternal db = null; ODatabaseDocumentInternal db = null;
if (ODatabaseRecordThreadLocal.INSTANCE != null) if (ODatabaseRecordThreadLocal.INSTANCE != null)
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


import java.io.IOException; import java.io.IOException;


public class OOpenRequest37 implements OBinaryRequest<OOpenResponse> { public class OOpenRequest37 implements OBinaryRequest<OOpenResponse37> {


private String clientId = null; private String clientId = null;
private boolean useToken = true; private boolean useToken = true;
Expand Down Expand Up @@ -82,7 +82,6 @@ public String getClientId() {
return clientId; return clientId;
} }



public boolean isCollectStats() { public boolean isCollectStats() {
return collectStats; return collectStats;
} }
Expand All @@ -101,8 +100,8 @@ public boolean requireDatabaseSession() {
} }


@Override @Override
public OOpenResponse createResponse() { public OOpenResponse37 createResponse() {
return new OOpenResponse(); return new OOpenResponse37();
} }


@Override @Override
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.orientechnologies.orient.client.remote.message;

import com.orientechnologies.orient.client.remote.OBinaryResponse;
import com.orientechnologies.orient.client.remote.OStorageRemoteSession;
import com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer;
import com.orientechnologies.orient.core.storage.OCluster;
import com.orientechnologies.orient.enterprise.channel.binary.OChannelBinaryProtocol;
import com.orientechnologies.orient.enterprise.channel.binary.OChannelDataInput;
import com.orientechnologies.orient.enterprise.channel.binary.OChannelDataOutput;

import java.io.IOException;
import java.util.Collection;

/**
* Created by tglman on 09/05/17.
*/
public class OOpenResponse37 implements OBinaryResponse {
private int sessionId;
private byte[] sessionToken;

public OOpenResponse37() {
}

public OOpenResponse37(int sessionId, byte[] sessionToken) {
this.sessionId = sessionId;
this.sessionToken = sessionToken;
}

@Override
public void write(OChannelDataOutput channel, int protocolVersion, ORecordSerializer serializer) throws IOException {
channel.writeInt(sessionId);
channel.writeBytes(sessionToken);
}

@Override
public void read(OChannelDataInput network, OStorageRemoteSession session) throws IOException {
sessionId = network.readInt();
sessionToken = network.readBytes();
}

public int getSessionId() {
return sessionId;
}

public byte[] getSessionToken() {
return sessionToken;
}
}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ public OBinaryResponse executeDatabaseOpen37(OOpenRequest37 request) {
distriConf = getRecordBytes(connection, distributedCfg); distriConf = getRecordBytes(connection, distributedCfg);
} }


return new OOpenResponse(connection.getId(), tokenToSend, clusters, distriConf, OConstants.getVersion()); return new OOpenResponse37(connection.getId(), tokenToSend);
} }


@Override @Override
Expand Down

0 comments on commit 11995eb

Please sign in to comment.