Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Madan Jampani
2014-11-12 01:06:51 -0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
44e6a540a50422def1be78428ad4e76e1c59b334
44e6a540
1 parent
23af4fc0
More checkstyle fixes.
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
87 additions
and
24 deletions
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseManager.java
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseStateMachine.java
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseUpdateEventHandler.java
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseUpdateEventListener.java
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DistributedLock.java
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DistributedLockManager.java
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/TableModificationEvent.java
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseManager.java
View file @
44e6a54
...
...
@@ -228,76 +228,89 @@ public class DatabaseManager implements DatabaseService, DatabaseAdminService {
@Override
public
boolean
putIfAbsent
(
String
tableName
,
String
key
,
byte
[]
value
)
{
BatchWriteRequest
batchRequest
=
new
BatchWriteRequest
.
Builder
().
putIfAbsent
(
tableName
,
key
,
value
).
build
();
BatchWriteRequest
batchRequest
=
new
BatchWriteRequest
.
Builder
()
.
putIfAbsent
(
tableName
,
key
,
value
).
build
();
WriteResult
writeResult
=
batchWrite
(
batchRequest
).
getAsList
().
get
(
0
);
if
(
writeResult
.
status
().
equals
(
WriteStatus
.
OK
))
{
return
true
;
}
else
if
(
writeResult
.
status
().
equals
(
WriteStatus
.
PRECONDITION_VIOLATION
))
{
return
false
;
}
throw
new
DatabaseException
(
"putIfAbsent failed due to status: "
+
writeResult
.
status
());
throw
new
DatabaseException
(
"putIfAbsent failed due to status: "
+
writeResult
.
status
());
}
@Override
public
boolean
putIfVersionMatches
(
String
tableName
,
String
key
,
byte
[]
value
,
long
version
)
{
BatchWriteRequest
batchRequest
=
new
BatchWriteRequest
.
Builder
().
putIfVersionMatches
(
tableName
,
key
,
value
,
version
).
build
();
BatchWriteRequest
batchRequest
=
new
BatchWriteRequest
.
Builder
()
.
putIfVersionMatches
(
tableName
,
key
,
value
,
version
).
build
();
WriteResult
writeResult
=
batchWrite
(
batchRequest
).
getAsList
().
get
(
0
);
if
(
writeResult
.
status
().
equals
(
WriteStatus
.
OK
))
{
return
true
;
}
else
if
(
writeResult
.
status
().
equals
(
WriteStatus
.
PRECONDITION_VIOLATION
))
{
return
false
;
}
throw
new
DatabaseException
(
"putIfVersionMatches failed due to status: "
+
writeResult
.
status
());
throw
new
DatabaseException
(
"putIfVersionMatches failed due to status: "
+
writeResult
.
status
());
}
@Override
public
boolean
putIfValueMatches
(
String
tableName
,
String
key
,
byte
[]
oldValue
,
byte
[]
newValue
)
{
BatchWriteRequest
batchRequest
=
new
BatchWriteRequest
.
Builder
().
putIfValueMatches
(
tableName
,
key
,
oldValue
,
newValue
).
build
();
BatchWriteRequest
batchRequest
=
new
BatchWriteRequest
.
Builder
()
.
putIfValueMatches
(
tableName
,
key
,
oldValue
,
newValue
).
build
();
WriteResult
writeResult
=
batchWrite
(
batchRequest
).
getAsList
().
get
(
0
);
if
(
writeResult
.
status
().
equals
(
WriteStatus
.
OK
))
{
return
true
;
}
else
if
(
writeResult
.
status
().
equals
(
WriteStatus
.
PRECONDITION_VIOLATION
))
{
return
false
;
}
throw
new
DatabaseException
(
"putIfValueMatches failed due to status: "
+
writeResult
.
status
());
throw
new
DatabaseException
(
"putIfValueMatches failed due to status: "
+
writeResult
.
status
());
}
@Override
public
VersionedValue
remove
(
String
tableName
,
String
key
)
{
BatchWriteRequest
batchRequest
=
new
BatchWriteRequest
.
Builder
().
remove
(
tableName
,
key
).
build
();
BatchWriteRequest
batchRequest
=
new
BatchWriteRequest
.
Builder
()
.
remove
(
tableName
,
key
).
build
();
WriteResult
writeResult
=
batchWrite
(
batchRequest
).
getAsList
().
get
(
0
);
if
(
writeResult
.
status
().
equals
(
WriteStatus
.
OK
))
{
return
writeResult
.
previousValue
();
}
throw
new
DatabaseException
(
"remove failed due to status: "
+
writeResult
.
status
());
throw
new
DatabaseException
(
"remove failed due to status: "
+
writeResult
.
status
());
}
@Override
public
boolean
removeIfVersionMatches
(
String
tableName
,
String
key
,
long
version
)
{
BatchWriteRequest
batchRequest
=
new
BatchWriteRequest
.
Builder
().
removeIfVersionMatches
(
tableName
,
key
,
version
).
build
();
BatchWriteRequest
batchRequest
=
new
BatchWriteRequest
.
Builder
()
.
removeIfVersionMatches
(
tableName
,
key
,
version
).
build
();
WriteResult
writeResult
=
batchWrite
(
batchRequest
).
getAsList
().
get
(
0
);
if
(
writeResult
.
status
().
equals
(
WriteStatus
.
OK
))
{
return
true
;
}
else
if
(
writeResult
.
status
().
equals
(
WriteStatus
.
PRECONDITION_VIOLATION
))
{
return
false
;
}
throw
new
DatabaseException
(
"removeIfVersionMatches failed due to status: "
+
writeResult
.
status
());
throw
new
DatabaseException
(
"removeIfVersionMatches failed due to status: "
+
writeResult
.
status
());
}
@Override
public
boolean
removeIfValueMatches
(
String
tableName
,
String
key
,
byte
[]
value
)
{
BatchWriteRequest
batchRequest
=
new
BatchWriteRequest
.
Builder
().
removeIfValueMatches
(
tableName
,
key
,
value
).
build
();
BatchWriteRequest
batchRequest
=
new
BatchWriteRequest
.
Builder
()
.
removeIfValueMatches
(
tableName
,
key
,
value
).
build
();
WriteResult
writeResult
=
batchWrite
(
batchRequest
).
getAsList
().
get
(
0
);
if
(
writeResult
.
status
().
equals
(
WriteStatus
.
OK
))
{
return
true
;
}
else
if
(
writeResult
.
status
().
equals
(
WriteStatus
.
PRECONDITION_VIOLATION
))
{
return
false
;
}
throw
new
DatabaseException
(
"removeIfValueMatches failed due to status: "
+
writeResult
.
status
());
throw
new
DatabaseException
(
"removeIfValueMatches failed due to status: "
+
writeResult
.
status
());
}
@Override
...
...
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseStateMachine.java
View file @
44e6a54
...
...
@@ -47,7 +47,7 @@ public class DatabaseStateMachine implements StateMachine {
private
final
Logger
log
=
getLogger
(
getClass
());
// message subject for database update notifications.
public
static
MessageSubject
DATABASE_UPDATE_EVENTS
=
public
static
final
MessageSubject
DATABASE_UPDATE_EVENTS
=
new
MessageSubject
(
"database-update-events"
);
// serializer used for snapshot
...
...
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseUpdateEventHandler.java
View file @
44e6a54
...
...
@@ -38,11 +38,16 @@ import org.onlab.onos.store.service.DatabaseService;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
DatabaseUpdateEventHandler
implements
DatabaseUpdateEventListener
,
EventHandler
<
LeaderElectEvent
>
{
/**
* Database update event handler.
*/
public
class
DatabaseUpdateEventHandler
implements
DatabaseUpdateEventListener
,
EventHandler
<
LeaderElectEvent
>
{
private
final
Logger
log
=
LoggerFactory
.
getLogger
(
getClass
());
public
final
static
MessageSubject
DATABASE_UPDATES
=
new
MessageSubject
(
"database-update-event"
);
public
static
final
MessageSubject
DATABASE_UPDATES
=
new
MessageSubject
(
"database-update-event"
);
private
DatabaseService
databaseService
;
private
ClusterService
cluster
;
...
...
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseUpdateEventListener.java
View file @
44e6a54
...
...
@@ -16,23 +16,26 @@
package
org
.
onlab
.
onos
.
store
.
service
.
impl
;
/**
* Interface of database update event listeners.
*/
public
interface
DatabaseUpdateEventListener
{
/**
*
* @param event
*
Notifies listeners of a table modified event.
* @param event
table modification event.
*/
public
void
tableModified
(
TableModificationEvent
event
);
/**
*
*
Notifies listeners of a table created event.
* @param tableName
* @param expirationTimeMillis
*/
public
void
tableCreated
(
String
tableName
,
int
expirationTimeMillis
);
/**
*
*
Notifies listeners of a table deleted event.
* @param tableName
*/
public
void
tableDeleted
(
String
tableName
);
...
...
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DistributedLock.java
View file @
44e6a54
...
...
@@ -69,7 +69,7 @@ public class DistributedLock implements Lock {
public
boolean
tryLock
(
long
waitTimeMillis
,
int
leaseDurationMillis
)
{
if
(
tryLock
(
leaseDurationMillis
)
==
false
)
{
if
(
!
tryLock
(
leaseDurationMillis
)
)
{
CompletableFuture
<
Void
>
future
=
lockManager
.
lockIfAvailable
(
this
,
waitTimeMillis
,
leaseDurationMillis
);
try
{
...
...
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DistributedLockManager.java
View file @
44e6a54
...
...
@@ -80,7 +80,10 @@ public class DistributedLockManager implements LockService {
throw
new
UnsupportedOperationException
();
}
protected
CompletableFuture
<
Void
>
lockIfAvailable
(
Lock
lock
,
long
waitTimeMillis
,
int
leaseDurationMillis
)
{
protected
CompletableFuture
<
Void
>
lockIfAvailable
(
Lock
lock
,
long
waitTimeMillis
,
int
leaseDurationMillis
)
{
CompletableFuture
<
Void
>
future
=
new
CompletableFuture
<>();
locksToAcquire
.
put
(
lock
.
path
(),
...
...
@@ -103,7 +106,9 @@ public class DistributedLockManager implements LockService {
if
(
event
.
type
()
==
TableModificationEvent
.
Type
.
ROW_DELETED
)
{
List
<
LockRequest
>
existingRequests
=
locksToAcquire
.
get
(
path
);
if
(
existingRequests
==
null
)
return
;
if
(
existingRequests
==
null
)
{
return
;
}
Iterator
<
LockRequest
>
existingRequestIterator
=
existingRequests
.
iterator
();
while
(
existingRequestIterator
.
hasNext
())
{
...
...
@@ -111,7 +116,7 @@ public class DistributedLockManager implements LockService {
if
(
request
.
expirationTime
().
isAfter
(
DateTime
.
now
()))
{
existingRequestIterator
.
remove
();
}
else
{
if
(
request
.
lock
().
tryLock
(
request
.
leaseDurationMillis
())
==
true
)
{
if
(
request
.
lock
().
tryLock
(
request
.
leaseDurationMillis
()))
{
request
.
future
().
complete
(
null
);
existingRequests
.
remove
(
0
);
}
...
...
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/TableModificationEvent.java
View file @
44e6a54
package
org
.
onlab
.
onos
.
store
.
service
.
impl
;
public
class
TableModificationEvent
{
/**
* A table modification event.
*/
public
final
class
TableModificationEvent
{
/**
* Type of table modification event.
*
*/
public
enum
Type
{
ROW_ADDED
,
ROW_DELETED
,
...
...
@@ -12,14 +19,32 @@ public class TableModificationEvent {
private
final
String
key
;
private
final
Type
type
;
/**
* Creates a new row deleted table modification event.
* @param tableName table name.
* @param key row key
* @return table modification event.
*/
public
static
TableModificationEvent
rowDeleted
(
String
tableName
,
String
key
)
{
return
new
TableModificationEvent
(
tableName
,
key
,
Type
.
ROW_DELETED
);
}
/**
* Creates a new row added table modification event.
* @param tableName table name.
* @param key row key
* @return table modification event.
*/
public
static
TableModificationEvent
rowAdded
(
String
tableName
,
String
key
)
{
return
new
TableModificationEvent
(
tableName
,
key
,
Type
.
ROW_ADDED
);
}
/**
* Creates a new row updated table modification event.
* @param tableName table name.
* @param key row key
* @return table modification event.
*/
public
static
TableModificationEvent
rowUpdated
(
String
tableName
,
String
key
)
{
return
new
TableModificationEvent
(
tableName
,
key
,
Type
.
ROW_UPDATED
);
}
...
...
@@ -30,14 +55,26 @@ public class TableModificationEvent {
this
.
type
=
type
;
}
/**
* Returns name of table this event is for.
* @return table name
*/
public
String
tableName
()
{
return
tableName
;
}
/**
* Returns the row key this event is for.
* @return row key
*/
public
String
key
()
{
return
key
;
}
/**
* Returns the type of table modification event.
* @return event type.
*/
public
Type
type
()
{
return
type
;
}
...
...
Please
register
or
login
to post a comment