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

Repair backups on ReadRepair #236

Closed
Closed
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
36 changes: 19 additions & 17 deletions internal/dmap/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,24 +238,26 @@ func (dm *DMap) readRepair(winner *version, versions []*version) {
// Sync
tmp := *version.host
if tmp.CompareByID(dm.s.rt.This()) {
hkey := partitions.HKey(dm.name, winner.entry.Key())
part := dm.getPartitionByHKey(hkey, partitions.PRIMARY)
f, err := dm.loadOrCreateFragment(part)
if err != nil {
dm.s.log.V(3).Printf("[ERROR] Failed to get or create the fragment for: %s on %s: %v",
winner.entry.Key(), dm.name, err)
return
}

f.Lock()
e := newEnv(context.Background())
e.hkey = hkey
e.fragment = f
err = dm.putEntryOnFragment(e, winner.entry)
if err != nil {
dm.s.log.V(3).Printf("[ERROR] Failed to synchronize with replica: %v", err)
for _, kind := range []partitions.Kind{partitions.PRIMARY, partitions.BACKUP} {
hkey := partitions.HKey(dm.name, winner.entry.Key())
part := dm.getPartitionByHKey(hkey, kind)
f, err := dm.loadOrCreateFragment(part)
if err != nil {
dm.s.log.V(3).Printf("[ERROR] Failed to get or create the fragment of kind %s for: %s on %s: %v",
kind.String(), winner.entry.Key(), dm.name, err)
return
}

f.Lock()
e := newEnv(context.Background())
e.hkey = hkey
e.fragment = f
err = dm.putEntryOnFragment(e, winner.entry)
if err != nil {
dm.s.log.V(3).Printf("[ERROR] Failed to synchronize with replica: %v", err)
}
f.Unlock()
}
f.Unlock()
} else {
// If readRepair is enabled, this function is called by every GET request.
cmd := protocol.NewPutEntry(dm.name, winner.entry.Key(), winner.entry.Encode()).Command(dm.s.ctx)
Expand Down
5 changes: 3 additions & 2 deletions internal/dmap/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ package dmap

import (
"context"
"testing"

"github.com/buraksezer/olric/internal/cluster/routingtable"
"github.com/buraksezer/olric/internal/testcluster"
"github.com/buraksezer/olric/internal/testutil"
"github.com/stretchr/testify/require"
"testing"
)

func TestDMap_Get_Standalone(t *testing.T) {
Expand Down Expand Up @@ -222,7 +223,7 @@ func TestDMap_Get_ReadRepair(t *testing.T) {
e3 := testcluster.NewEnvironment(c3)
s3 := cluster.AddMember(e3).(*Service)

// Call DMap.Get on S2
// Call DMap.Get on S3
dm2, err := s3.NewDMap("mydmap")
require.NoError(t, err)

Expand Down
Loading