mirror of https://github.com/docker/docs.git
Write ack and read mode for linearizability on tuf_files table
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
This commit is contained in:
parent
4385f46d90
commit
db5d1b6fb8
|
@ -140,7 +140,7 @@ func (rdb RethinkDB) UpdateMany(gun string, updates []MetaUpdate) error {
|
||||||
// the given GUN and role, an error is returned.
|
// the given GUN and role, an error is returned.
|
||||||
func (rdb RethinkDB) GetCurrent(gun, role string) (created *time.Time, data []byte, err error) {
|
func (rdb RethinkDB) GetCurrent(gun, role string) (created *time.Time, data []byte, err error) {
|
||||||
file := RDBTUFFile{}
|
file := RDBTUFFile{}
|
||||||
res, err := gorethink.DB(rdb.dbName).Table(file.TableName()).GetAllByIndex(
|
res, err := gorethink.DB(rdb.dbName).Table(file.TableName(), gorethink.TableOpts{ReadMode: "majority"}).GetAllByIndex(
|
||||||
rdbGunRoleIdx, []string{gun, role},
|
rdbGunRoleIdx, []string{gun, role},
|
||||||
).OrderBy(gorethink.Desc("version")).Run(rdb.sess)
|
).OrderBy(gorethink.Desc("version")).Run(rdb.sess)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -162,7 +162,7 @@ func (rdb RethinkDB) GetCurrent(gun, role string) (created *time.Time, data []by
|
||||||
// not found, it returns storage.ErrNotFound
|
// not found, it returns storage.ErrNotFound
|
||||||
func (rdb RethinkDB) GetChecksum(gun, role, checksum string) (created *time.Time, data []byte, err error) {
|
func (rdb RethinkDB) GetChecksum(gun, role, checksum string) (created *time.Time, data []byte, err error) {
|
||||||
var file RDBTUFFile
|
var file RDBTUFFile
|
||||||
res, err := gorethink.DB(rdb.dbName).Table(file.TableName()).GetAllByIndex(
|
res, err := gorethink.DB(rdb.dbName).Table(file.TableName(), gorethink.TableOpts{ReadMode: "majority"}).GetAllByIndex(
|
||||||
rdbGunRoleSha256Idx, []string{gun, role, checksum},
|
rdbGunRoleSha256Idx, []string{gun, role, checksum},
|
||||||
).Run(rdb.sess)
|
).Run(rdb.sess)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -21,6 +21,10 @@ var (
|
||||||
rdbGunRoleIdx: {"gun", "role"},
|
rdbGunRoleIdx: {"gun", "role"},
|
||||||
rdbGunRoleSha256Idx: {"gun", "role", "sha256"},
|
rdbGunRoleSha256Idx: {"gun", "role", "sha256"},
|
||||||
},
|
},
|
||||||
|
// this configuration guarantees linearizability of individual atomic operations on individual documents
|
||||||
|
Config: map[string]string{
|
||||||
|
"write_acks": "majority",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
keys = rethinkdb.Table{
|
keys = rethinkdb.Table{
|
||||||
|
|
|
@ -33,6 +33,7 @@ type Table struct {
|
||||||
// on the field matching the key. Otherwise, it is a compound index
|
// on the field matching the key. Otherwise, it is a compound index
|
||||||
// on the list of fields in the corrensponding slice value.
|
// on the list of fields in the corrensponding slice value.
|
||||||
SecondaryIndexes map[string][]string
|
SecondaryIndexes map[string][]string
|
||||||
|
Config map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Table) term(dbName string) gorethink.Term {
|
func (t Table) term(dbName string) gorethink.Term {
|
||||||
|
@ -75,6 +76,14 @@ func (t Table) create(session *gorethink.Session, dbName string, numReplicas uin
|
||||||
return fmt.Errorf("unable to wait for table to be ready after reconfiguring replication: %s", err)
|
return fmt.Errorf("unable to wait for table to be ready after reconfiguring replication: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := t.term(dbName).Config().Update(t.Config).RunWrite(session); err != nil {
|
||||||
|
return fmt.Errorf("unable to configure table linearizability: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := t.wait(session, dbName); err != nil {
|
||||||
|
return fmt.Errorf("unable to wait for table to be ready after configuring linearizability: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
for indexName, fieldNames := range t.SecondaryIndexes {
|
for indexName, fieldNames := range t.SecondaryIndexes {
|
||||||
if len(fieldNames) == 0 {
|
if len(fieldNames) == 0 {
|
||||||
// The field name is the index name.
|
// The field name is the index name.
|
||||||
|
@ -112,7 +121,7 @@ func (t Table) create(session *gorethink.Session, dbName string, numReplicas uin
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupDB hadles creating the database and creating all tables and indexes.
|
// SetupDB handles creating the database and creating all tables and indexes.
|
||||||
func SetupDB(session *gorethink.Session, dbName string, tables []Table) error {
|
func SetupDB(session *gorethink.Session, dbName string, tables []Table) error {
|
||||||
if err := makeDB(session, dbName); err != nil {
|
if err := makeDB(session, dbName); err != nil {
|
||||||
return fmt.Errorf("unable to create database: %s", err)
|
return fmt.Errorf("unable to create database: %s", err)
|
||||||
|
|
Loading…
Reference in New Issue