Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
hpdos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SYNERG
hpdos
Commits
484668c3
Commit
484668c3
authored
Apr 11, 2021
by
NILANJAN DAW
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Async HPDOS client library support
parent
6852c7fd
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
418 additions
and
151 deletions
+418
-151
code/hpdos_client/app.config
code/hpdos_client/app.config
+2
-2
code/hpdos_client/app/src/main/java/HpdosClient/ClientRunner.java
...os_client/app/src/main/java/HpdosClient/ClientRunner.java
+198
-138
code/hpdos_client/app/src/main/java/HpdosClient/MessageFormat/MessageConstants.java
...main/java/HpdosClient/MessageFormat/MessageConstants.java
+6
-2
code/hpdos_client/app/src/main/java/HpdosClient/lib/StorageModel.java
...lient/app/src/main/java/HpdosClient/lib/StorageModel.java
+104
-0
code/hpdos_client/app/src/main/java/HpdosClient/lib/StorageService.java
...ent/app/src/main/java/HpdosClient/lib/StorageService.java
+99
-0
code/hpdos_server/app/src/main/java/hpdos/handler/IOHandler.java
...dos_server/app/src/main/java/hpdos/handler/IOHandler.java
+5
-5
code/hpdos_server/app/src/main/java/hpdos/lib/MemoryStorageService.java
...ver/app/src/main/java/hpdos/lib/MemoryStorageService.java
+3
-3
code/hpdos_server/app/src/main/java/hpdos/message/MessageConstants.java
...ver/app/src/main/java/hpdos/message/MessageConstants.java
+1
-1
No files found.
code/hpdos_client/app.config
View file @
484668c3
app
.
name
=
"HPDOS-Client"
app
.
version
=
"0.1.4"
app
.
thread_count
=
4
app
.
runtime
=
1
app
.
concurrency
=
5
app
.
runtime
=
1
0
app
.
data_size
=
10
app
.
data_conversion_factor
=
B
app
.
private_ratio
=
0
.
8
...
...
code/hpdos_client/app/src/main/java/HpdosClient/ClientRunner.java
View file @
484668c3
This diff is collapsed.
Click to expand it.
code/hpdos_client/app/src/main/java/HpdosClient/MessageFormat/MessageConstants.java
View file @
484668c3
...
...
@@ -12,10 +12,14 @@ public class MessageConstants {
// Distinguishing ACK and NACK packets
public
static
final
int
STATUS_OK
=
200
;
public
static
final
int
STATUS_
OWNER_MISMATCH
=
401
;
public
static
final
int
STATUS_REPLICAT
E
_FAILED
=
402
;
public
static
final
int
STATUS_
UNAUTHORIZED_PRIVATE_KEY_ACCESS
=
401
;
public
static
final
int
STATUS_REPLICAT
ION
_FAILED
=
402
;
public
static
final
int
STATUS_SERVER_NOT_MASTER
=
403
;
public
static
final
int
STATUS_KEY_NOT_FOUND
=
404
;
public
static
final
int
STATUS_REPLICATION_TIMEOUT
=
405
;
public
static
final
int
STATUS_IO_WRITE_FAILED
=
406
;
public
static
final
int
STATUS_KEY_EXISTS
=
407
;
public
static
final
int
STATUS_UPDATE_VERSION_MISMATCH
=
408
;
// 100 to 199 - HPDOS System internal operations
public
static
final
int
MASTER_HEARTBEAT
=
100
;
...
...
code/hpdos_client/app/src/main/java/HpdosClient/lib/StorageModel.java
0 → 100644
View file @
484668c3
package
HpdosClient.lib
;
import
hpdos.grpc.Ack
;
import
java.util.zip.CRC32
;
import
java.util.zip.Checksum
;
public
class
StorageModel
{
private
int
version
;
private
int
dataSize
;
private
final
String
key
;
// key is immutable
private
long
crc
;
private
int
accessType
;
private
String
value
;
private
final
String
owner
;
// ownership is immutable
public
StorageModel
(
int
version
,
int
dataSize
,
String
key
,
int
accessType
,
String
owner
,
long
crc
,
String
value
)
{
this
.
version
=
version
;
this
.
dataSize
=
dataSize
;
this
.
key
=
key
;
this
.
accessType
=
accessType
;
this
.
value
=
value
;
this
.
owner
=
owner
;
// calculate CRC32 based on the value field
this
.
crc
=
crc
;
}
public
void
updateData
(
Ack
ack
)
{
this
.
version
=
ack
.
getVersion
();
this
.
dataSize
=
ack
.
getDataSize
();
this
.
value
=
ack
.
getValue
();
this
.
crc
=
ack
.
getCrc
();
}
public
int
getVersion
()
{
return
version
;
}
public
void
setVersion
(
int
version
)
{
this
.
version
=
version
;
}
public
int
getDataSize
()
{
return
dataSize
;
}
public
void
setDataSize
(
int
dataSize
)
{
this
.
dataSize
=
dataSize
;
}
public
String
getKey
()
{
return
key
;
}
public
long
getCrc
()
{
return
crc
;
}
public
void
setCrc
(
long
crc
)
{
this
.
crc
=
crc
;
}
public
int
getAccessType
()
{
return
accessType
;
}
public
void
setAccessType
(
int
accessType
)
{
this
.
accessType
=
accessType
;
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
public
String
getOwner
()
{
return
owner
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
obj
==
null
)
return
false
;
if
(
obj
.
getClass
()
!=
this
.
getClass
())
return
false
;
StorageModel
model
=
(
StorageModel
)
obj
;
return
this
.
getKey
().
equals
(
model
.
getKey
());
}
@Override
public
String
toString
()
{
return
"key: "
+
this
.
key
+
"\n"
+
"dataSize: "
+
this
.
dataSize
+
"\n"
+
"version: "
+
this
.
version
+
"\n"
+
"owner: "
+
this
.
owner
+
"\n"
+
"accessType: "
+
this
.
accessType
+
"\n"
+
"crc: "
+
this
.
crc
+
"\n"
+
"value: "
+
this
.
value
;
}
}
code/hpdos_client/app/src/main/java/HpdosClient/lib/StorageService.java
0 → 100644
View file @
484668c3
package
HpdosClient.lib
;
import
HpdosClient.ConfigConstants
;
import
HpdosClient.MessageFormat.MessageConstants
;
import
HpdosClient.MessageFormat.RequestBuilder
;
import
com.google.common.util.concurrent.ListenableFuture
;
import
hpdos.grpc.*
;
import
io.grpc.ManagedChannel
;
import
io.grpc.ManagedChannelBuilder
;
import
java.util.*
;
public
class
StorageService
{
private
final
String
clientID
;
private
ManagedChannel
masterChannel
;
private
ArrayList
<
ManagedChannel
>
channels
;
private
NetworkServiceGrpc
.
NetworkServiceFutureStub
masterStub
;
private
final
ArrayList
<
NetworkServiceGrpc
.
NetworkServiceFutureStub
>
stubs
;
private
List
<
Follower
>
replicaSet
;
public
StorageService
(
String
clientID
)
{
this
.
clientID
=
clientID
;
this
.
stubs
=
new
ArrayList
<>();
}
public
void
retrieveFollowerList
()
{
NetworkServiceGrpc
.
NetworkServiceBlockingStub
stub
=
NetworkServiceGrpc
.
newBlockingStub
(
this
.
masterChannel
);
ResponseList
responseList
=
stub
.
getReadReplicaList
(
null
);
this
.
replicaSet
=
responseList
.
getFollowerList
();
// for (Follower follower: this.replicaSet) {
// System.out.println(follower);
// }
}
public
void
cleanup
()
{
for
(
ManagedChannel
channel:
this
.
channels
)
channel
.
shutdown
();
}
public
void
initStorage
()
{
masterChannel
=
ManagedChannelBuilder
.
forAddress
(
ConfigConstants
.
HOST
,
ConfigConstants
.
PORT
)
.
usePlaintext
()
.
build
();
channels
=
new
ArrayList
<>();
channels
.
add
(
masterChannel
);
masterStub
=
NetworkServiceGrpc
.
newFutureStub
(
this
.
masterChannel
);
retrieveFollowerList
();
for
(
Follower
follower:
replicaSet
)
{
ManagedChannel
channel
=
ManagedChannelBuilder
.
forAddress
(
follower
.
getIp
(),
follower
.
getPort
())
.
usePlaintext
()
.
build
();
channels
.
add
(
channel
);
NetworkServiceGrpc
.
NetworkServiceFutureStub
stub
=
NetworkServiceGrpc
.
newFutureStub
(
channel
);
stubs
.
add
(
stub
);
}
}
public
ListenableFuture
<
Packet
>
create
(
String
key
,
String
value
,
int
accessType
)
{
ArrayList
<
Request
>
request
=
new
ArrayList
<>();
request
.
add
(
RequestBuilder
.
buildRequest
(
MessageConstants
.
METADATA_CREATE
,
0
,
value
.
length
(),
key
,
0
,
accessType
,
this
.
clientID
,
value
));
Packet
packet
=
RequestBuilder
.
buildPacket
(
request
);
return
this
.
masterStub
.
createMetadata
(
packet
);
}
public
ListenableFuture
<
Packet
>
read
(
String
key
)
{
int
rnd
=
new
Random
().
nextInt
(
this
.
stubs
.
size
());
NetworkServiceGrpc
.
NetworkServiceFutureStub
stub
=
this
.
stubs
.
get
(
rnd
);
ArrayList
<
Request
>
request
=
new
ArrayList
<>();
request
.
add
(
RequestBuilder
.
buildRequest
(
MessageConstants
.
METADATA_READ
,
0
,
0
,
key
,
0
,
MessageConstants
.
METADATA_ACCESS_PRIVATE
,
this
.
clientID
,
""
));
Packet
packet
=
RequestBuilder
.
buildPacket
(
request
);
return
stub
.
readMetadata
(
packet
);
}
public
ListenableFuture
<
Packet
>
update
(
String
key
,
String
value
,
int
version
)
{
ArrayList
<
Request
>
request
=
new
ArrayList
<>();
request
.
add
(
RequestBuilder
.
buildRequest
(
MessageConstants
.
METADATA_UPDATE
,
version
,
value
.
length
(),
key
,
0
,
MessageConstants
.
METADATA_ACCESS_PRIVATE
,
this
.
clientID
,
value
));
Packet
packet
=
RequestBuilder
.
buildPacket
(
request
);
return
this
.
masterStub
.
updateMetadata
(
packet
);
}
public
ListenableFuture
<
Packet
>
delete
(
String
key
,
int
version
)
{
ArrayList
<
Request
>
request
=
new
ArrayList
<>();
request
.
add
(
RequestBuilder
.
buildRequest
(
MessageConstants
.
METADATA_DELETE
,
version
,
0
,
key
,
0
,
MessageConstants
.
METADATA_ACCESS_PRIVATE
,
this
.
clientID
,
""
));
Packet
packet
=
RequestBuilder
.
buildPacket
(
request
);
return
this
.
masterStub
.
deleteMetadata
(
packet
);
}
}
code/hpdos_server/app/src/main/java/hpdos/handler/IOHandler.java
View file @
484668c3
...
...
@@ -66,7 +66,7 @@ public class IOHandler {
storedData
.
getData
().
getValue
());
return
ResponseBuilder
.
buildResponsePacket
(
MessageConstants
.
METADATA_
CRE
ATE
,
MessageConstants
.
STATUS_OK
,
MessageConstants
.
METADATA_
UPD
ATE
,
MessageConstants
.
STATUS_OK
,
ack
,
null
);
}
else
{
...
...
@@ -74,7 +74,7 @@ public class IOHandler {
storedData
.
getData
().
getVersion
():
MessageConstants
.
INVALID_VERSION
;
nack
=
ResponseBuilder
.
buildNack
(
version
,
request
.
getKey
());
return
ResponseBuilder
.
buildResponsePacket
(
MessageConstants
.
METADATA_
CRE
ATE
,
storedData
.
getStatus
(),
MessageConstants
.
METADATA_
UPD
ATE
,
storedData
.
getStatus
(),
null
,
nack
);
}
}
...
...
@@ -102,7 +102,7 @@ public class IOHandler {
storedData
.
getData
().
getValue
());
return
ResponseBuilder
.
buildResponsePacket
(
MessageConstants
.
METADATA_
CREA
TE
,
MessageConstants
.
STATUS_OK
,
MessageConstants
.
METADATA_
DELE
TE
,
MessageConstants
.
STATUS_OK
,
ack
,
null
);
}
else
{
...
...
@@ -110,7 +110,7 @@ public class IOHandler {
storedData
.
getData
().
getVersion
():
MessageConstants
.
INVALID_VERSION
;
nack
=
ResponseBuilder
.
buildNack
(
version
,
request
.
getKey
());
return
ResponseBuilder
.
buildResponsePacket
(
MessageConstants
.
METADATA_
CREA
TE
,
storedData
.
getStatus
(),
MessageConstants
.
METADATA_
DELE
TE
,
storedData
.
getStatus
(),
null
,
nack
);
}
}
...
...
@@ -145,7 +145,7 @@ public class IOHandler {
}
}
return
ResponseBuilder
.
buildResponsePacket
(
MessageConstants
.
METADATA_
CREATE
,
status
,
MessageConstants
.
METADATA_
READ
,
status
,
ack
,
nack
);
}
}
code/hpdos_server/app/src/main/java/hpdos/lib/MemoryStorageService.java
View file @
484668c3
...
...
@@ -43,9 +43,9 @@ public class MemoryStorageService implements StorageService {
boolean
status
=
memoryKVStore
.
replace
(
key
,
value
,
newValue
);
// the equals method is overridden in Storage model
// to equate two objects based on their version numbers
if
(
status
)
return
new
StoredModel
(
v
alue
,
MessageConstants
.
STATUS_OK
);
return
new
StoredModel
(
newV
alue
,
MessageConstants
.
STATUS_OK
);
else
return
new
StoredModel
(
null
,
MessageConstants
.
STATUS_UPDATE_VERSION_MISMATCH
);
return
new
StoredModel
(
previousValue
,
MessageConstants
.
STATUS_UPDATE_VERSION_MISMATCH
);
}
@Override
...
...
@@ -60,6 +60,6 @@ public class MemoryStorageService implements StorageService {
if
(
status
)
return
new
StoredModel
(
previousValue
,
MessageConstants
.
STATUS_OK
);
else
return
new
StoredModel
(
null
,
MessageConstants
.
STATUS_UPDATE_VERSION_MISMATCH
);
return
new
StoredModel
(
previousValue
,
MessageConstants
.
STATUS_UPDATE_VERSION_MISMATCH
);
}
}
code/hpdos_server/app/src/main/java/hpdos/message/MessageConstants.java
View file @
484668c3
...
...
@@ -2,7 +2,7 @@ package hpdos.message;
public
class
MessageConstants
{
public
static
final
int
INIT_VERSION
=
0
;
public
static
final
int
INIT_VERSION
=
1
;
public
static
final
int
INVALID_VERSION
=
-
1
;
public
static
final
int
METADATA_ACCESS_PRIVATE
=
700
;
public
static
final
int
METADATA_ACCESS_SHARED
=
777
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment