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

Remove unnecessary locks from TabletInfo #198

Merged
Merged
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
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
Loading