Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entrega Lab 2 #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions common/consistenthash/consistenthash.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ type Ring struct {
// search will find the index of the node that is responsible for the range that
// includes the hashed value of key.
func (r *Ring) search(key string) int {
/////////////////////////
// YOUR CODE GOES HERE //
/////////////////////////

return 0

// alterado
sfunc := func(i int) bool {
return r.Nodes[i].HashId >= hashId(key)
return r.Nodes[0]
}
return sort.Search(r.Nodes.Len(), sfunc)
// alterado
//return 0
}

// NewRing will create a new Ring object and return a pointer to it.
Expand Down
15 changes: 7 additions & 8 deletions dynamo/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import (
"sync"
)

///////////////////////////////
// THIS FILE IS MISSING CODE //
///////////////////////////////

// Cache is the struct that handle all the data storage for the dynamo server.
type Cache struct {
data map[string]string
data map[string]string
time map[string]int64 // alterado
sync.Mutex
}

Expand All @@ -20,7 +17,7 @@ func NewCache() *Cache {
var s Cache

s.data = make(map[string]string)

s.time = make(map[string]int64) // alterado
return &s
}

Expand All @@ -29,7 +26,7 @@ func NewCache() *Cache {
func (cache *Cache) Get(key string) (value string, timestamp int64) {
cache.Lock()
value = cache.data[key]
timestamp = 0
timestamp = cache.time[key] // alterado
cache.Unlock()

log.Printf("[CACHE] Getting Key '%v' with Value '%v' @ timestamp '%v'\n", key, value, timestamp)
Expand All @@ -43,6 +40,7 @@ func (cache *Cache) Put(key string, value string, timestamp int64) {

cache.Lock()
cache.data[key] = value
cache.time[key] = timestamp // alterado
cache.Unlock()

return
Expand All @@ -52,6 +50,7 @@ func (cache *Cache) Put(key string, value string, timestamp int64) {
// except for testing purposes.
func (cache *Cache) getAll() (data map[string]string, timestamps map[string]int64) {
data = cache.data
timestamps = make(map[string]int64)
//timestamps = make(map[string]int64) // alterado
timestamps = cache.time // alterado
return data, timestamps
}
13 changes: 10 additions & 3 deletions dynamo/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,16 @@ func aggregateVotes(votes []*vote) (result string) {
log.Printf("[COORDINATOR] Vote: %v\n", vote.value)
}

/////////////////////////
// YOUR CODE GOES HERE //
/////////////////////////
// alterado
var latestStamp int64 = votes[0].timestamp
result = votes[0].value
for _, vote := range votes {
if vote.timestamp > latestStamp {
latestStamp = vote.timestamp
result = vote.value
}
}
// alterado

return
}