Commit 61493bc7 authored by Paras Garg's avatar Paras Garg

Updated

parent d16dbc01
Set up disni
export LD_LIBRARY_PATH=/usr/local/lib
How to setup RocksDB jar How to setup RocksDB jar
1. Compiling RocksDb java from source code 1. Compiling RocksDb java from source code
make -j8 rocksjava DEBUG_LEVEL=0 make -j8 rocksjava DEBUG_LEVEL=0
......
app.HOST=192.168.200.20 app.HOST=192.168.200.20
app.MASTER=true app.MASTER=true
app.cpu_affinity=4 #this is how to pair threads to cpu cores
app.cpu_affinity=2
//No of thread for each connectin
app.rdma_cluster_size=1
app.rdma_receive_queue=16 app.rdma_receive_queue=16
app.rdma_send_queue=16 app.rdma_send_queue=16
app.rdma_polling=false app.rdma_polling=false
......
app.HOST=192.168.200.20 app.HOST=192.168.200.20
app.MASTER=false app.MASTER=false
app.cpu_affinity=4 app.cpu_affinity=4
app.rdma_cluster_size=3
app.rdma_receive_queue=16 app.rdma_receive_queue=16
app.rdma_send_queue=16 app.rdma_send_queue=16
app.rdma_polling=false app.rdma_polling=false
...@@ -8,6 +9,7 @@ app.rdma_max_inline=0 ...@@ -8,6 +9,7 @@ app.rdma_max_inline=0
app.rdma_server_port=1921 app.rdma_server_port=1921
app.NETWORK_HANDLER_THREADS=10 app.NETWORK_HANDLER_THREADS=10
app.REPLICATION_HANDLER_THREADS=10 app.REPLICATION_HANDLER_THREADS=10
app.db_path=/tmp/rocks
#The below properties are for master node only. #The below properties are for master node only.
app.follower_registration_port=9876 app.follower_registration_port=9876
......
apply plugin: "application" apply plugin: "application"
apply plugin: "java-library" apply plugin: "java-library"
application mainClassName = "hpdos_rdma_offloaded.MetadataServer"
{
mainClassName = "hpdos_rdma_offloaded.MetadataServer"
}
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
repositories repositories
......
package hpdos_rdma_offloaded; package hpdos_rdma_offloaded;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Properties; import java.util.Properties;
...@@ -18,13 +20,15 @@ import hpdos_rdma_offloaded.handler.RegistrationHandler; ...@@ -18,13 +20,15 @@ import hpdos_rdma_offloaded.handler.RegistrationHandler;
import hpdos_rdma_offloaded.handler.StorageHandler; import hpdos_rdma_offloaded.handler.StorageHandler;
import hpdos_rdma_offloaded.protocol.Request; import hpdos_rdma_offloaded.protocol.Request;
import hpdos_rdma_offloaded.protocol.Response; import hpdos_rdma_offloaded.protocol.Response;
import hpdos_rdma_offloaded.service.MetadataServerService; import hpdos_rdma_offloaded.service.FollowerMetadataService;
import hpdos_rdma_offloaded.service.MasterMetadataServerService;
public class MetadataServer implements Runnable{ public class MetadataServer implements Runnable{
private String host; private String host;
private int poolsize; private int poolsize;
private int recvQueue; private int recvQueue;
private int sendQueue; private int sendQueue;
private int clusterSize;
private int wqSize = recvQueue; private int wqSize = recvQueue;
private boolean polling; private boolean polling;
private int maxinline = 0; private int maxinline = 0;
...@@ -34,49 +38,68 @@ public class MetadataServer implements Runnable{ ...@@ -34,49 +38,68 @@ public class MetadataServer implements Runnable{
boolean isMaster; boolean isMaster;
StorageHandler storageHandler; StorageHandler storageHandler;
NetworkHandler networkHandler; NetworkHandler networkHandler;
MetadataServerService metadataServerService; MasterMetadataServerService metadataServerService = null;
FollowerMetadataService followerMetadataServerService = null;
RegistrationHandler registrationHandler = null; RegistrationHandler registrationHandler = null;
public final static Properties properties= new Properties();; public final static Properties properties= new Properties();
String propertyPath;
public MetadataServer(String propertyPath) throws IOException,RocksDBException { public MetadataServer(String propertyPath) throws Exception,RocksDBException {
this.propertyPath = propertyPath;
InputStream inputStream = new FileInputStream(propertyPath); InputStream inputStream = new FileInputStream(propertyPath);
properties.load(inputStream); properties.load(inputStream);
boolean isMaster = Boolean.valueOf((String)properties.get("app.MASTER")); this.isMaster = Boolean.valueOf((String)properties.get("app.MASTER"));
if(isMaster)
{
System.out.println("STARTING MASTER SERVICES.");
}
else
{
System.out.println("STARTING FOLLOWER SERVICES.");
}
isMaster = Boolean.valueOf((String)properties.get("app.MASTER"));
storageHandler = new StorageHandler(properties.getProperty("app.db_path"));
networkHandler = new NetworkHandler(this.storageHandler, properties);
metadataServerService = new MetadataServerService(this.networkHandler);
registrationHandler = new RegistrationHandler(properties);
host = (String) properties.get("app.HOST"); host = properties.getProperty("app.HOST");
poolsize = Integer.valueOf( (String)properties.get("app.cpu_affinity")); poolsize = Integer.valueOf( properties.getProperty("app.cpu_affinity"));
recvQueue = Integer.valueOf( (String)properties.get("app.rdma_receive_queue")); recvQueue = Integer.valueOf(properties.getProperty("app.rdma_receive_queue"));
sendQueue = Integer.valueOf( (String) properties.get("app.rdma_send_queue")); sendQueue = Integer.valueOf( properties.getProperty("app.rdma_send_queue"));
clusterSize = Integer.valueOf(properties.getProperty("app.rdma_cluster_size"));
wqSize = recvQueue; wqSize = recvQueue;
maxinline = Integer.valueOf((String) properties.get("app.rdma_max_inline")); maxinline = Integer.valueOf(properties.getProperty("app.rdma_max_inline"));
rdma_port = Integer.valueOf((String) properties.get("app.rdma_server_port")); rdma_port = Integer.valueOf(properties.getProperty("app.rdma_server_port"));
polling = Boolean.valueOf((String) properties.get("app.rdma_polling")); polling = Boolean.valueOf(properties.getProperty("app.rdma_polling"));
int registrationPort = Integer.valueOf(properties.getProperty("app.follower_registration_port"));
clusterAffinities = new long[poolsize]; clusterAffinities = new long[poolsize];
for (int i = 0; i < poolsize; i++) for (int i = 0; i < poolsize; i++)
{ {
long cpu = 1L << i; long cpu = 1L << i;
clusterAffinities[i] = cpu; clusterAffinities[i] = cpu;
System.out.println(cpu);
}
isMaster = Boolean.valueOf(properties.getProperty("app.MASTER"));
storageHandler = new StorageHandler(properties.getProperty("app.db_path"));
networkHandler = new NetworkHandler(isMaster);
// metadataServerService = new MasterMetadataServerService(this.networkHandler,storageHandler);
registrationHandler = new RegistrationHandler(isMaster,host,registrationPort, networkHandler);
if(isMaster)
{
System.out.println("STARTING MASTER SERVICES.");
metadataServerService = new MasterMetadataServerService(this.networkHandler,storageHandler);
}
else
{
System.out.println("STARTING FOLLOWER SERVICES.");
followerMetadataServerService = new FollowerMetadataService(storageHandler);
} }
} }
public void run(){ public void run(){
// MetadataServerService rpcService = new MetadataServerService(); // MetadataServerService rpcService = new MetadataServerService();
DaRPCServerGroup<Request, Response> group = null; DaRPCServerGroup<Request, Response> group = null;
try try
{ {
group = DaRPCServerGroup.createServerGroup(this.metadataServerService, this.clusterAffinities, -1, maxinline, polling, recvQueue, sendQueue, wqSize, 32); if (isMaster) {
group = DaRPCServerGroup.createServerGroup(this.metadataServerService, this.clusterAffinities, 1000, maxinline, polling, recvQueue, sendQueue, wqSize, clusterSize);
} else {
group = DaRPCServerGroup.createServerGroup(this.followerMetadataServerService, this.clusterAffinities, 1000, maxinline, polling, recvQueue, sendQueue, wqSize, clusterSize);
}
RdmaServerEndpoint<DaRPCServerEndpoint<Request, Response>> serverEp = null; RdmaServerEndpoint<DaRPCServerEndpoint<Request, Response>> serverEp = null;
serverEp = group.createServerEndpoint(); serverEp = group.createServerEndpoint();
InetSocketAddress address = new InetSocketAddress(host, rdma_port); InetSocketAddress address = new InetSocketAddress(host, rdma_port);
...@@ -102,7 +125,10 @@ public class MetadataServer implements Runnable{ ...@@ -102,7 +125,10 @@ public class MetadataServer implements Runnable{
public static void main(String[] args) throws Exception public static void main(String[] args) throws Exception
{ {
RocksDB.loadLibrary(); RocksDB.loadLibrary();
new MetadataServer(args[0]).run(); //var process = Runtime.getRuntime().exec("/bin/sh export LD_LIBRARY_PATH=/usr/local/lib");
System.out.println("Rocksdb Exception occur"); //process.wait();
// System.out.println("Exit value "+process.exitValue());
Runnable r = new MetadataServer(args[0]);
new Thread(r).start();
} }
} }
...@@ -7,31 +7,34 @@ import java.lang.ClassNotFoundException; ...@@ -7,31 +7,34 @@ import java.lang.ClassNotFoundException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.util.Properties;
import java.util.UUID; import java.util.UUID;
public class RegistrationHandler { public class RegistrationHandler {
public ServerSocket server; public ServerSocket server;
public int port = 9876; public int port = 9876;
boolean isMaster; boolean isMaster;
String registrationServerIp;
int follower_registration_port; int follower_registration_port;
int sal_registration_port; int sal_registration_port;
NetworkHandler networkHandler;
public RegistrationHandler(Properties properties) throws IOException {
this.isMaster = Boolean.valueOf((String)properties.get("app.MASTER"));
if (this.isMaster) { public RegistrationHandler(boolean isMaster, String registrationServerIP, int registrationPort, NetworkHandler networkHandler) throws IOException {
this.follower_registration_port = Integer.valueOf((String)properties.get("app.follower_registration_port")); this.registrationServerIp = registrationServerIP;
this.sal_registration_port = Integer.valueOf((String)properties.get("app.follower_registration_port")); this.follower_registration_port = 9876;
this.sal_registration_port = 9875;
this.networkHandler = networkHandler;
if (isMaster)
{
startFollowerRegistrationHandlerServer(); startFollowerRegistrationHandlerServer();
startSalRegistrationHandlerServer(); startSalRegistrationHandlerServer();
} else { }
else {
// Follower follower = new Follower(); // Follower follower = new Follower();
// follower.setFollowerId( UUID.randomUUID().toString()); // follower.setFollowerId( UUID.randomUUID().toString());
// follower.setIpAddress("192.168.200.20"); // follower.setIpAddress("192.168.200.20");
String followerUUID = UUID.randomUUID().toString(); String followerUUID = UUID.randomUUID().toString();
String followerIp = "192.168.200.20"; String followerIp = registrationServerIP;
String message = followerUUID + ";" + followerIp; String message = followerUUID + ";" + followerIp;
sendRegistrationRequest(message); sendRegistrationRequest(message);
} }
...@@ -39,10 +42,10 @@ public class RegistrationHandler { ...@@ -39,10 +42,10 @@ public class RegistrationHandler {
private void sendRegistrationRequest(String message) throws IOException { private void sendRegistrationRequest(String message) throws IOException {
System.out.println("Sending a registration request"); System.out.println("Sending a registration request");
InetAddress host = InetAddress.getByName("192.168.200.20"); InetAddress host = InetAddress.getByName(this.registrationServerIp);
Socket socket = null; Socket socket = null;
ObjectOutputStream oos = null; ObjectOutputStream oos = null;
socket = new Socket(host.getHostName(), 9876); socket = new Socket(this.registrationServerIp, 9876);
oos = new ObjectOutputStream(socket.getOutputStream()); oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(message); oos.writeObject(message);
} }
...@@ -50,10 +53,12 @@ public class RegistrationHandler { ...@@ -50,10 +53,12 @@ public class RegistrationHandler {
public void startFollowerRegistrationHandlerServer(){ public void startFollowerRegistrationHandlerServer(){
Runnable serverTask = new Runnable() { Runnable serverTask = new Runnable() {
@Override @Override
public void run() { public void run()
try { {
InetAddress addr = InetAddress.getByName("192.168.200.20"); try
ServerSocket serverSocket = new ServerSocket(9876, 50, addr); {
InetAddress addr = InetAddress.getByName(registrationServerIp);
ServerSocket serverSocket = new ServerSocket(follower_registration_port, 50, addr);
System.out.println("Started the follower registration service..."); System.out.println("Started the follower registration service...");
while (true) { while (true) {
Socket socket = serverSocket.accept(); Socket socket = serverSocket.accept();
...@@ -65,8 +70,8 @@ public class RegistrationHandler { ...@@ -65,8 +70,8 @@ public class RegistrationHandler {
String followerIp = arr[1]; String followerIp = arr[1];
System.out.println("Got follower ip: " + followerIp + " , with UUID of: " + followerUUID); System.out.println("Got follower ip: " + followerIp + " , with UUID of: " + followerUUID);
NetworkHandler networkHandler = new NetworkHandler(); NetworkHandler networkHandler = new NetworkHandler();
networkHandler.connectToFollower(followerUUID, followerIp); networkHandler.connectToFollower(followerUUID, followerIp);
System.out.println("RDMA connection establised"); System.out.println("RDMA connection establised");
// Add the follower details to the respective class/component // Add the follower details to the respective class/component
// clientProcessingPool.submit(new ClientTask(clientSocket)); // clientProcessingPool.submit(new ClientTask(clientSocket));
...@@ -86,16 +91,18 @@ public class RegistrationHandler { ...@@ -86,16 +91,18 @@ public class RegistrationHandler {
@Override @Override
public void run() { public void run() {
try { try {
ServerSocket serverSocket = new ServerSocket(9875); InetAddress addr = InetAddress.getByName(registrationServerIp);
ServerSocket serverSocket = new ServerSocket(sal_registration_port, 50, addr);
System.out.println("Started the SAL registration service..."); System.out.println("Started the SAL registration service...");
while (true) { while (true) {
Socket socket = serverSocket.accept(); Socket socket = serverSocket.accept();
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream()); ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
String message = (String) ois.readObject(); String ip = (String) ois.readObject();
// Send a response back with the list of followers to the SAL NetworkHandler networkHandler = new NetworkHandler();
networkHandler.connectToSal(ip);
// clientProcessingPool.submit(new ClientTask(clientSocket)); // clientProcessingPool.submit(new ClientTask(clientSocket));
} }
} catch (IOException | ClassNotFoundException e) { } catch (Exception e) {
System.err.println("Unable to process client request"); System.err.println("Unable to process client request");
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -4,6 +4,9 @@ import org.rocksdb.RocksDB; ...@@ -4,6 +4,9 @@ import org.rocksdb.RocksDB;
import org.rocksdb.Options; import org.rocksdb.Options;
import org.rocksdb.RocksDBException; import org.rocksdb.RocksDBException;
import hpdos_rdma_offloaded.protocol.Request;
public class StorageHandler implements AutoCloseable{ public class StorageHandler implements AutoCloseable{
RocksDB rocksDB; RocksDB rocksDB;
...@@ -27,16 +30,32 @@ public class StorageHandler implements AutoCloseable{ ...@@ -27,16 +30,32 @@ public class StorageHandler implements AutoCloseable{
public void create(byte[] key,byte[] value) throws RocksDBException{ public void create(byte[] key,byte[] value) throws RocksDBException{
rocksDB.put(key,value); rocksDB.put(key,value);
} }
public void create(Request request) throws RocksDBException {
System.out.println("Writing to local");
rocksDB.put(request.getKey(),request.getValue());
}
public byte[] read(byte[] key)throws RocksDBException public byte[] read(byte[] key)throws RocksDBException
{ {
return rocksDB.get(key); return rocksDB.get(key);
} }
public byte[] read(Request request)throws RocksDBException
{
return rocksDB.get(request.getKey());
}
public void update(byte[] key,byte[] value) throws RocksDBException public void update(byte[] key,byte[] value) throws RocksDBException
{ {
rocksDB.put(key,value); rocksDB.put(key,value);
} }
public void update(Request request) throws RocksDBException
{
rocksDB.put(request.getKey(),request.getValue());
}
public void delete(byte[] key) throws RocksDBException public void delete(byte[] key) throws RocksDBException
{ {
rocksDB.delete(key); rocksDB.delete(key);
} }
public void delete(Request request) throws RocksDBException
{
rocksDB.delete(request.getKey());
}
} }
\ No newline at end of file
...@@ -6,6 +6,8 @@ public interface AckType ...@@ -6,6 +6,8 @@ public interface AckType
public static int NOTFOUND = 1; public static int NOTFOUND = 1;
public static int NOTALLOWED = 2; public static int NOTALLOWED = 2;
public static int DBFAILED = 3; public static int DBFAILED = 3;
public static int SUCCESS_WITH_VALUE = 4; public static int FAILED = 4;
public static int SUCCESS_WITH_VALUE = 5;
public static int INVALID_REQUEST = 6;
} }
\ No newline at end of file
package hpdos_rdma_offloaded.rdma_invalidation_protocol; package hpdos_rdma_offloaded.protocol;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
...@@ -6,34 +6,31 @@ import java.nio.ByteBuffer; ...@@ -6,34 +6,31 @@ import java.nio.ByteBuffer;
import com.ibm.darpc.DaRPCMessage; import com.ibm.darpc.DaRPCMessage;
public class InvalidationRequest implements DaRPCMessage { public class InvalidationRequest implements DaRPCMessage {
public String key; public byte[] key;
private static char[] dst = new char[100]; private static int SERIALIZED_SIZE = 128 ;
private int SERIALIZED_SIZE = 256;
@Override @Override
public int write(ByteBuffer buffer) throws IOException { public int write(ByteBuffer buffer) throws IOException {
buffer.asCharBuffer().put(key); buffer.put(key);
return SERIALIZED_SIZE; return SERIALIZED_SIZE;
} }
@Override @Override
public void update(ByteBuffer buffer) throws IOException { public void update(ByteBuffer buffer) throws IOException {
buffer.asCharBuffer().get(dst, 0, 99); if(key == null)
String s = new String(dst); key = new byte[128];
s = s.trim(); buffer.get(key);
key = s;
} }
@Override @Override
public int size() { public int size() {
return SERIALIZED_SIZE; return SERIALIZED_SIZE;
} }
public String getKey() { public byte[] getKey() {
return key; return key;
} }
public void setKey(String key) { public void setKey(byte[] key) {
this.key = key; this.key = key;
} }
} }
package hpdos_rdma_offloaded.rdma_invalidation_protocol; package hpdos_rdma_offloaded.protocol;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
...@@ -6,23 +6,32 @@ import java.nio.ByteBuffer; ...@@ -6,23 +6,32 @@ import java.nio.ByteBuffer;
import com.ibm.darpc.DaRPCMessage; import com.ibm.darpc.DaRPCMessage;
public class InvalidationResponse implements DaRPCMessage{ public class InvalidationResponse implements DaRPCMessage{
public static int SERIALIZED_SIZE = 4;
private int ack;
@Override @Override
public int write(ByteBuffer buffer) throws IOException { public int write(ByteBuffer buffer) throws IOException
{
buffer.putInt(ack);
return 0; return 0;
} }
@Override @Override
public void update(ByteBuffer buffer) throws IOException { public void update(ByteBuffer buffer) throws IOException
{
buffer.getInt(ack);
} }
@Override @Override
public int size() { public int size() {
return 0; return SERIALIZED_SIZE;
}
public void setAck(int ack){
this.ack = ack;
}
public int getAck()
{
return this.ack;
} }
} }
package hpdos_rdma_offloaded.rdma_invalidation_protocol; package hpdos_rdma_offloaded.protocol;
import com.ibm.darpc.DaRPCProtocol; import com.ibm.darpc.DaRPCProtocol;
......
...@@ -16,7 +16,7 @@ public class Request implements DaRPCMessage ...@@ -16,7 +16,7 @@ public class Request implements DaRPCMessage
@Override @Override
public int write(ByteBuffer buffer) throws IOException public int write(ByteBuffer buffer) throws IOException
{ {
System.out.println("Request Write Method"); // System.out.println("Request Write Method");
buffer.putInt(requestType); buffer.putInt(requestType);
buffer.put(key); buffer.put(key);
//if operation type is get and delete then value is not required //if operation type is get and delete then value is not required
...@@ -33,7 +33,7 @@ public class Request implements DaRPCMessage ...@@ -33,7 +33,7 @@ public class Request implements DaRPCMessage
@Override @Override
public void update(ByteBuffer buffer) throws IOException public void update(ByteBuffer buffer) throws IOException
{ {
System.out.println("Request update method"); // System.out.println("Request update method");
requestType = buffer.getInt(); requestType = buffer.getInt();
if(key == null || key.length != 128) if(key == null || key.length != 128)
this.key = new byte[128]; this.key = new byte[128];
......
...@@ -2,8 +2,8 @@ package hpdos_rdma_offloaded.protocol; ...@@ -2,8 +2,8 @@ package hpdos_rdma_offloaded.protocol;
public interface RequestType public interface RequestType
{ {
public static int GET =101;
public static int PUT =100; public static int PUT =100;
public static int GET =101;
public static int DELETE =102; public static int DELETE =102;
public static int INVALIDATE = 103; public static int INVALIDATE = 103;
......
...@@ -14,7 +14,7 @@ public class Response implements DaRPCMessage{ ...@@ -14,7 +14,7 @@ public class Response implements DaRPCMessage{
@Override @Override
public int write(ByteBuffer buffer) throws IOException public int write(ByteBuffer buffer) throws IOException
{ {
System.out.println("Response write Method"); // System.out.println("Response write Method");
buffer.putInt(ack); buffer.putInt(ack);
if(ack == AckType.SUCCESS_WITH_VALUE) if(ack == AckType.SUCCESS_WITH_VALUE)
{ {
...@@ -27,7 +27,7 @@ public class Response implements DaRPCMessage{ ...@@ -27,7 +27,7 @@ public class Response implements DaRPCMessage{
@Override @Override
public void update(ByteBuffer buffer) throws IOException public void update(ByteBuffer buffer) throws IOException
{ {
System.out.println("esponse update method"); // System.out.println("esponse update method");
ack = buffer.getInt(); ack = buffer.getInt();
if(ack == AckType.SUCCESS_WITH_VALUE) if(ack == AckType.SUCCESS_WITH_VALUE)
{ {
......
package hpdos_rdma_offloaded.service; package hpdos_rdma_offloaded.service;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.ExecutionException;
import com.ibm.darpc.DaRPCClientGroup;
import com.ibm.darpc.DaRPCServerEndpoint; import com.ibm.darpc.DaRPCServerEndpoint;
import com.ibm.darpc.DaRPCServerEvent; import com.ibm.darpc.DaRPCServerEvent;
import com.ibm.darpc.DaRPCService; import com.ibm.darpc.DaRPCService;
import org.rocksdb.RocksDBException; import org.rocksdb.RocksDBException;
import hpdos_rdma_offloaded.handler.NetworkHandler; import hpdos_rdma_offloaded.handler.StorageHandler;
import hpdos_rdma_offloaded.lib.Packet; import hpdos_rdma_offloaded.lib.Packet;
import hpdos_rdma_offloaded.protocol.AckType; import hpdos_rdma_offloaded.protocol.AckType;
import hpdos_rdma_offloaded.protocol.InvalidationRequest;
import hpdos_rdma_offloaded.protocol.InvalidationResponse;
import hpdos_rdma_offloaded.protocol.Request; import hpdos_rdma_offloaded.protocol.Request;
import hpdos_rdma_offloaded.protocol.RequestType; import hpdos_rdma_offloaded.protocol.RequestType;
import hpdos_rdma_offloaded.protocol.Response; import hpdos_rdma_offloaded.protocol.Response;
import hpdos_rdma_offloaded.protocol.RpcProtocol; import hpdos_rdma_offloaded.protocol.RpcProtocol;
public class MetadataServerService extends RpcProtocol implements DaRPCService<Request, Response>{ public class FollowerMetadataService extends RpcProtocol implements DaRPCService<Request, Response>{
NetworkHandler networkHandler; StorageHandler storageHandler;
DaRPCClientGroup<InvalidationRequest, InvalidationResponse> invalidationClientGroup;
public MetadataServerService(NetworkHandler networkHandler){ public FollowerMetadataService(StorageHandler storageHandler) throws Exception{
this.networkHandler = networkHandler; System.out.println("New MetadataServerService Created");
this.storageHandler = storageHandler;
} }
@Override @Override
public void processServerEvent(DaRPCServerEvent<Request, Response> event) throws IOException { public void processServerEvent(DaRPCServerEvent<Request, Response> event) throws IOException {
Request request = event.getReceiveMessage(); Request request = event.getReceiveMessage();
Response response = event.getSendMessage(); Response response = event.getSendMessage();
if (request.getRequestType() == RequestType.PUT) {
// Write code for create System.out.print("Received "+request.getRequestType()+" Request for key: " + new String(request.getKey()));
Packet packet = new Packet(request.getRequestType(), request.getKey(), request.getValue()); if(request.getValue() != null)
try System.out.print(" value : "+ new String(request.getValue()) );
{ System.out.println();
this.networkHandler.create(packet);
try{
if (request.getRequestType() == RequestType.PUT) {
this.storageHandler.create(request);
response.setAck(AckType.SUCCESS); response.setAck(AckType.SUCCESS);
response.setKey(null); response.setKey(null);
response.setValue(null); response.setValue(null);
} }
catch(RocksDBException ex) else if(request.getRequestType() == RequestType.GET) {
{ byte[] value = this.storageHandler.read(request);
ex.printStackTrace();
response.setAck(AckType.DBFAILED);
}
catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
else if(request.getRequestType() == RequestType.GET) {
Packet packet = new Packet(request.getRequestType(), request.getKey(), null);
try
{
byte[] value = this.networkHandler.read(packet);
if(value == null) if(value == null)
{ {
response.setAck(AckType.NOTFOUND); response.setAck(AckType.NOTFOUND);
...@@ -62,37 +56,24 @@ public class MetadataServerService extends RpcProtocol implements DaRPCService<R ...@@ -62,37 +56,24 @@ public class MetadataServerService extends RpcProtocol implements DaRPCService<R
response.setValue(value); response.setValue(value);
} }
} }
catch(RocksDBException ex) else if(request.getRequestType() == RequestType.DELETE){
{ this.storageHandler.delete(request);
ex.printStackTrace();
response.setAck(AckType.DBFAILED);
}
catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
// Write code for read
}
else if(request.getRequestType() == RequestType.DELETE){
try{
Packet packet = new Packet(request.getRequestType(), request.getKey(), null);
this.networkHandler.delete(packet);
response.setAck(AckType.SUCCESS); response.setAck(AckType.SUCCESS);
} }
catch(RocksDBException ex) else{
{ response.setAck(AckType.INVALID_REQUEST);
}
}
catch(RocksDBException ex){
ex.printStackTrace(); ex.printStackTrace();
response.setAck(AckType.DBFAILED); response.setAck(AckType.DBFAILED);
}catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
// Write code for delete
} }
event.triggerResponse(); event.triggerResponse();
} }
@Override @Override
public void open(DaRPCServerEndpoint<Request, Response> rpcClientEndpoint) { public void open(DaRPCServerEndpoint<Request, Response> rpcClientEndpoint) {
System.out.println("Received new connection..."); System.out.print("Received new connection ");
} }
@Override @Override
......
package hpdos_rdma_offloaded.service;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import com.ibm.darpc.DaRPCClientEndpoint;
import com.ibm.darpc.DaRPCClientGroup;
import com.ibm.darpc.DaRPCServerEndpoint;
import com.ibm.darpc.DaRPCServerEvent;
import com.ibm.darpc.DaRPCService;
import com.ibm.darpc.DaRPCStream;
import org.rocksdb.RocksDBException;
import hpdos_rdma_offloaded.handler.NetworkHandler;
import hpdos_rdma_offloaded.handler.StorageHandler;
import hpdos_rdma_offloaded.lib.Packet;
import hpdos_rdma_offloaded.protocol.AckType;
import hpdos_rdma_offloaded.protocol.InvalidationRequest;
import hpdos_rdma_offloaded.protocol.InvalidationResponse;
import hpdos_rdma_offloaded.protocol.InvalidationRpcProtocol;
import hpdos_rdma_offloaded.protocol.Request;
import hpdos_rdma_offloaded.protocol.RequestType;
import hpdos_rdma_offloaded.protocol.Response;
import hpdos_rdma_offloaded.protocol.RpcProtocol;
public class MasterMetadataServerService extends RpcProtocol implements DaRPCService<Request, Response>{
NetworkHandler networkHandler;
StorageHandler storageHandler;
ConcurrentHashMap<SocketAddress,DaRPCStream<InvalidationRequest, InvalidationResponse>> invalidationClientEpStreams;
ConcurrentHashMap<SocketAddress,DaRPCClientEndpoint<InvalidationRequest, InvalidationResponse>> invalidationClientEps;
DaRPCClientGroup<InvalidationRequest, InvalidationResponse> invalidationClientGroup;
public MasterMetadataServerService(NetworkHandler networkHandler,StorageHandler storageHandler) throws Exception{
System.out.println("New MetadataServerService Created");
this.networkHandler = networkHandler;
this.storageHandler = storageHandler;
this.invalidationClientEpStreams = new ConcurrentHashMap<>();
this.invalidationClientEps = new ConcurrentHashMap<>();
this.networkHandler.setClientStreams(this.invalidationClientEpStreams);
InvalidationRpcProtocol rpcProtocol = new InvalidationRpcProtocol();
invalidationClientGroup = DaRPCClientGroup.createClientGroup(rpcProtocol, 100, 0, 16, 16);
}
@Override
public void processServerEvent(DaRPCServerEvent<Request, Response> event) throws IOException {
Request request = event.getReceiveMessage();
Response response = event.getSendMessage();
Packet packet = new Packet(request.getRequestType(), request.getKey(), request.getValue());
System.out.print("Received "+request.getRequestType()+" Request for key: " + new String(request.getKey()));
if(request.getValue() != null)
System.out.print(" value : "+ new String(request.getValue()) );
System.out.println();
try{
if (request.getRequestType() == RequestType.PUT) {
this.storageHandler.create(request);
this.networkHandler.create(packet);
this.networkHandler.sendInvalidateRequest(request);
//Yet to consume isDone
// var isDone = this.networkHandler.consumeReplicationRequestFutures(replicationRequestFutures);
response.setAck(AckType.SUCCESS);
response.setKey(null);
response.setValue(null);
}
else if(request.getRequestType() == RequestType.GET) {
byte[] value = this.storageHandler.read(request);
if(value == null)
{
response.setAck(AckType.NOTFOUND);
}
else
{
response.setAck(AckType.SUCCESS_WITH_VALUE);
response.setValue(value);
}
}
else if(request.getRequestType() == RequestType.DELETE){
this.storageHandler.delete(request);
// var replicationRequestFutures = this.networkHandler.sendReplicateRequest(request);
//Yet to consume isDone
// var isDone = this.networkHandler.consumeReplicationRequestFutures(replicationRequestFutures);
response.setAck(AckType.SUCCESS);
}
else{
response.setAck(AckType.INVALID_REQUEST);
}
}
catch(RocksDBException | InterruptedException | ExecutionException ex){
ex.printStackTrace();
response.setAck(AckType.DBFAILED);
}
event.triggerResponse();
}
@Override
public void open(DaRPCServerEndpoint<Request, Response> rpcClientEndpoint) {
System.out.print("Received new connection ");
// try{
// System.out.println(rpcClientEndpoint.getDstAddr()+" "+rpcClientEndpoint.getSrcAddr());
// String clientIP = ((InetSocketAddress)rpcClientEndpoint.getDstAddr()).getHostName();
// InetSocketAddress clientSocketAddress = new InetSocketAddress(clientIP,1921);
// System.out.println("Creating Endpoint");
// var invalidationClientEp = invalidationClientGroup.createEndpoint();
// invalidationClientEp.connect(clientSocketAddress, 100);
// System.out.println("accepted");
// if(invalidationClientEp.isConnected()){
// invalidationClientEpStreams.put(rpcClientEndpoint.getDstAddr(),invalidationClientEp.createStream());
// invalidationClientEps.put(rpcClientEndpoint.getDstAddr(),invalidationClientEp);
// }
// else{
// System.out.println("Not able to Connect to client for invalidation");
// }
// }
// catch(Exception e){
// e.printStackTrace();
// }
}
@Override
public void close(DaRPCServerEndpoint<Request, Response> rpcClientEndpoint) {
System.out.println("Closing Connection");
// try
// {
// invalidationClientEpStreams.remove(rpcClientEndpoint.getDstAddr());
// invalidationClientEps.remove(rpcClientEndpoint.getDstAddr()).close();
// System.out.println("After remove"+invalidationClientEpStreams.size());
// }catch(Exception e)
// {
// e.printStackTrace();
// }
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment