Skip to content

Commit

Permalink
Merge pull request #198 from dkropachev/dk/fix-remove-tabletinfo-locks
Browse files Browse the repository at this point in the history
Remove unnecessary locks from TabletInfo
  • Loading branch information
sylwiaszunejko authored Jun 25, 2024
2 parents dce12c1 + f4b0d94 commit 1551b70
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 47 deletions.
11 changes: 0 additions & 11 deletions host_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ type ReplicaInfo struct {

// Experimental, this interface and use may change
type TabletInfo struct {
mu sync.RWMutex
keyspaceName string
tableName string
firstToken int64
Expand All @@ -521,32 +520,22 @@ type TabletInfo struct {
}

func (t *TabletInfo) KeyspaceName() string {
t.mu.RLock()
defer t.mu.RUnlock()
return t.keyspaceName
}

func (t *TabletInfo) FirstToken() int64 {
t.mu.RLock()
defer t.mu.RUnlock()
return t.firstToken
}

func (t *TabletInfo) LastToken() int64 {
t.mu.RLock()
defer t.mu.RUnlock()
return t.lastToken
}

func (t *TabletInfo) TableName() string {
t.mu.RLock()
defer t.mu.RUnlock()
return t.tableName
}

func (t *TabletInfo) Replicas() []ReplicaInfo {
t.mu.RLock()
defer t.mu.RUnlock()
return t.replicas
}

Expand Down
36 changes: 0 additions & 36 deletions tablet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,133 +4,116 @@
package gocql

import (
"sync"
"testing"
)

var tablets = []*TabletInfo{
{
sync.RWMutex{},
"test1",
"table1",
-7917529027641081857,
-6917529027641081857,
[]ReplicaInfo{{TimeUUID(), 9}},
},
{
sync.RWMutex{},
"test1",
"table1",
-6917529027641081857,
-4611686018427387905,
[]ReplicaInfo{{TimeUUID(), 8}},
},
{
sync.RWMutex{},
"test1",
"table1",
-4611686018427387905,
-2305843009213693953,
[]ReplicaInfo{{TimeUUID(), 9}},
},
{
sync.RWMutex{},
"test1",
"table1",
-2305843009213693953,
-1,
[]ReplicaInfo{{TimeUUID(), 8}},
},
{
sync.RWMutex{},
"test1",
"table1",
-1,
2305843009213693951,
[]ReplicaInfo{{TimeUUID(), 3}},
},
{
sync.RWMutex{},
"test1",
"table1",
2305843009213693951,
4611686018427387903,
[]ReplicaInfo{{TimeUUID(), 3}},
},
{
sync.RWMutex{},
"test1",
"table1",
4611686018427387903,
6917529027641081855,
[]ReplicaInfo{{TimeUUID(), 7}},
},
{
sync.RWMutex{},
"test1",
"table1",
6917529027641081855,
9223372036854775807,
[]ReplicaInfo{{TimeUUID(), 7}},
},
{
sync.RWMutex{},
"test2",
"table1",
-7917529027641081857,
-6917529027641081857,
[]ReplicaInfo{{TimeUUID(), 9}},
},
{
sync.RWMutex{},
"test2",
"table1",
-6917529027641081857,
-4611686018427387905,
[]ReplicaInfo{{TimeUUID(), 8}},
},
{
sync.RWMutex{},
"test2",
"table1",
-4611686018427387905,
-2305843009213693953,
[]ReplicaInfo{{TimeUUID(), 9}},
},
{
sync.RWMutex{},
"test2",
"table1",
-2305843009213693953,
-1,
[]ReplicaInfo{{TimeUUID(), 8}},
},
{
sync.RWMutex{},
"test2",
"table1",
-1,
2305843009213693951,
[]ReplicaInfo{{TimeUUID(), 3}},
},
{
sync.RWMutex{},
"test2",
"table1",
2305843009213693951,
4611686018427387903,
[]ReplicaInfo{{TimeUUID(), 3}},
},
{
sync.RWMutex{},
"test2",
"table1",
4611686018427387903,
6917529027641081855,
[]ReplicaInfo{{TimeUUID(), 7}},
},
{
sync.RWMutex{},
"test2",
"table1",
6917529027641081855,
Expand Down Expand Up @@ -180,7 +163,6 @@ func TestAddTabletToEmptyTablets(t *testing.T) {
tablets := []*TabletInfo{}

tablets = addTabletToTabletsList(tablets, &TabletInfo{
sync.RWMutex{},
"test_ks",
"test_tb",
-6917529027641081857,
Expand All @@ -193,7 +175,6 @@ func TestAddTabletToEmptyTablets(t *testing.T) {

func TestAddTabletAtTheBeggining(t *testing.T) {
tablets := []*TabletInfo{{
sync.RWMutex{},
"test_ks",
"test_tb",
-6917529027641081857,
Expand All @@ -202,7 +183,6 @@ func TestAddTabletAtTheBeggining(t *testing.T) {
}}

tablets = addTabletToTabletsList(tablets, &TabletInfo{
sync.RWMutex{},
"test_ks",
"test_tb",
-8611686018427387905,
Expand All @@ -216,7 +196,6 @@ func TestAddTabletAtTheBeggining(t *testing.T) {

func TestAddTabletAtTheEnd(t *testing.T) {
tablets := []*TabletInfo{{
sync.RWMutex{},
"test_ks",
"test_tb",
-6917529027641081857,
Expand All @@ -225,7 +204,6 @@ func TestAddTabletAtTheEnd(t *testing.T) {
}}

tablets = addTabletToTabletsList(tablets, &TabletInfo{
sync.RWMutex{},
"test_ks",
"test_tb",
-1,
Expand All @@ -239,14 +217,12 @@ func TestAddTabletAtTheEnd(t *testing.T) {

func TestAddTabletInTheMiddle(t *testing.T) {
tablets := []*TabletInfo{{
sync.RWMutex{},
"test_ks",
"test_tb",
-6917529027641081857,
-4611686018427387905,
[]ReplicaInfo{},
}, {
sync.RWMutex{},
"test_ks",
"test_tb",
-1,
Expand All @@ -255,7 +231,6 @@ func TestAddTabletInTheMiddle(t *testing.T) {
}}

tablets = addTabletToTabletsList(tablets, &TabletInfo{
sync.RWMutex{},
"test_ks",
"test_tb",
-4611686018427387905,
Expand All @@ -270,28 +245,24 @@ func TestAddTabletInTheMiddle(t *testing.T) {

func TestAddTabletIntersecting(t *testing.T) {
tablets := []*TabletInfo{{
sync.RWMutex{},
"test_ks",
"test_tb",
-6917529027641081857,
-4611686018427387905,
[]ReplicaInfo{},
}, {
sync.RWMutex{},
"test_ks",
"test_tb",
-4611686018427387905,
-2305843009213693953,
[]ReplicaInfo{},
}, {
sync.RWMutex{},
"test_ks",
"test_tb",
-2305843009213693953,
-1,
[]ReplicaInfo{},
}, {
sync.RWMutex{},
"test_ks",
"test_tb",
-1,
Expand All @@ -300,7 +271,6 @@ func TestAddTabletIntersecting(t *testing.T) {
}}

tablets = addTabletToTabletsList(tablets, &TabletInfo{
sync.RWMutex{},
"test_ks",
"test_tb",
-3611686018427387905,
Expand All @@ -316,14 +286,12 @@ func TestAddTabletIntersecting(t *testing.T) {

func TestAddTabletIntersectingWithFirst(t *testing.T) {
tablets := []*TabletInfo{{
sync.RWMutex{},
"test_ks",
"test_tb",
-8611686018427387905,
-7917529027641081857,
[]ReplicaInfo{},
}, {
sync.RWMutex{},
"test_ks",
"test_tb",
-6917529027641081857,
Expand All @@ -332,7 +300,6 @@ func TestAddTabletIntersectingWithFirst(t *testing.T) {
}}

tablets = addTabletToTabletsList(tablets, &TabletInfo{
sync.RWMutex{},
"test_ks",
"test_tb",
-8011686018427387905,
Expand All @@ -346,14 +313,12 @@ func TestAddTabletIntersectingWithFirst(t *testing.T) {

func TestAddTabletIntersectingWithLast(t *testing.T) {
tablets := []*TabletInfo{{
sync.RWMutex{},
"test_ks",
"test_tb",
-8611686018427387905,
-7917529027641081857,
[]ReplicaInfo{},
}, {
sync.RWMutex{},
"test_ks",
"test_tb",
-6917529027641081857,
Expand All @@ -362,7 +327,6 @@ func TestAddTabletIntersectingWithLast(t *testing.T) {
}}

tablets = addTabletToTabletsList(tablets, &TabletInfo{
sync.RWMutex{},
"test_ks",
"test_tb",
-5011686018427387905,
Expand Down

0 comments on commit 1551b70

Please sign in to comment.