Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ECE 428 - Distributed Systems
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
djq2
ECE 428 - Distributed Systems
Commits
6d215bb9
Commit
6d215bb9
authored
3 years ago
by
djq2
Browse files
Options
Downloads
Patches
Plain Diff
more
parent
64a11a66
Branches
overtime
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mp3/src/servers/coordinator.go
+24
-6
24 additions, 6 deletions
mp3/src/servers/coordinator.go
mp3/src/servers/server.go
+1
-0
1 addition, 0 deletions
mp3/src/servers/server.go
with
25 additions
and
6 deletions
mp3/src/servers/coordinator.go
+
24
−
6
View file @
6d215bb9
...
...
@@ -96,7 +96,11 @@ func (host *Server) LockAccount(key string, ltype string) bool {
acc
.
Upgrade
.
Lock
()
acc
.
RW
.
RLock
()
acc
.
Upgrade
.
Unlock
()
acc
.
ReaderLock
.
Lock
()
acc
.
Readers
++
acc
.
LockType
=
"R"
acc
.
ReaderLock
.
Unlock
()
// fmt.Println("Couldnt get lock after 50 attempts.")
}
else
{
...
...
@@ -122,6 +126,7 @@ func (host *Server) LockAccount(key string, ltype string) bool {
acc
.
Upgrade
.
Lock
()
acc
.
RW
.
Lock
()
acc
.
Upgrade
.
Unlock
()
acc
.
LockType
=
"W"
// fmt.Println("Couldnt get lock after 50 attempts.")
...
...
@@ -177,12 +182,24 @@ func (host *Server) Release(account string, commit bool) bool {
// Read Lock
if
acc
.
LockType
==
"R"
{
acc
.
LockType
=
""
acc
.
ReaderLock
.
Lock
()
acc
.
Readers
--
if
acc
.
Readers
==
0
{
acc
.
LockType
=
""
}
acc
.
ReaderLock
.
Unlock
()
acc
.
RW
.
RUnlock
()
// Write Lock
}
else
{
acc
.
LockType
=
""
acc
.
ReaderLock
.
Lock
()
if
acc
.
Readers
==
0
{
acc
.
LockType
=
""
}
else
{
acc
.
LockType
=
"R"
}
acc
.
ReaderLock
.
Unlock
()
acc
.
RW
.
Unlock
()
}
...
...
@@ -528,7 +545,7 @@ func (host *Server) withdraw(operation Client_msg) {
val
.
Balance
-=
operation
.
Amount
host
.
Tr
.
Accounts
[
local_key
]
=
val
// Lock not "W", need upgrade
// Lock not "W", need upgrade
}
else
{
// Local upgrade
if
operation
.
Branch
==
host
.
Id
{
...
...
@@ -537,14 +554,14 @@ func (host *Server) withdraw(operation Client_msg) {
val
.
LockType
=
"W"
host
.
Tr
.
Accounts
[
local_key
]
=
val
// Remote upgrade
// Remote upgrade
}
else
{
req_out
.
Request
=
"UPGRADE"
go
host
.
server_write
(
operation
.
Branch
,
req_out
)
resp_in
:=
<-
host
.
Trans_chan
if
resp_in
.
Status
{
val
.
Balance
+
=
operation
.
Amount
val
.
Balance
-
=
operation
.
Amount
val
.
LockType
=
"W"
host
.
Tr
.
Accounts
[
local_key
]
=
val
}
else
{
...
...
@@ -646,7 +663,7 @@ func (host *Server) balance(operation Client_msg) {
host
.
abort
()
return
// Else grab read lock
// Else grab read lock
}
else
{
realAcc
:=
cast
.
(
*
Account
)
...
...
@@ -770,6 +787,7 @@ func (host *Server) commit() {
// POSSIBLE TIMING ISSUE IF FUNCTION ENDS WHILE STILL WAITING ON CHANNEL RESPONSES
go
host
.
server_write
(
data
.
Branch
,
msg_out
)
}
}
...
...
This diff is collapsed.
Click to expand it.
mp3/src/servers/server.go
+
1
−
0
View file @
6d215bb9
...
...
@@ -74,6 +74,7 @@ type Account struct{
LockType
string
// "R" or "W"
Readers
int
Committed
bool
// True if account has new, but uncommitted - May need to add conditional wait
ReaderLock
*
sync
.
Mutex
}
// type Msg struct{ // For testing
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment