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

Add back tranmutex #153

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
21 changes: 18 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ type ovndb struct {
client *libovsdb.OvsdbClient
cache map[string]map[string]libovsdb.Row
cachemutex sync.RWMutex
tranmutex sync.RWMutex
signalCB OVNSignal
disconnectCB OVNDisconnectedCallback
db string
Expand Down Expand Up @@ -359,6 +360,8 @@ func (c *ovndb) reconnect() {
ticker := time.NewTicker(500 * time.Millisecond)
go func() {
log.Printf("%s disconnected. Reconnecting ... \n", c.addr)
c.tranmutex.Lock()
defer c.tranmutex.Unlock()
retry := 0
for range ticker.C {
if err := connect(c); err != nil {
Expand Down Expand Up @@ -391,7 +394,7 @@ func (c *ovndb) filterTablesFromSchema() []string {
tables = SBTablesOrder
}

dbSchema := c.GetSchema()
dbSchema := c.getSchema(c.db)
schemaTables := make([]string, 0)
for _, table := range tables {
if _, ok := dbSchema.Tables[table]; ok {
Expand Down Expand Up @@ -442,13 +445,25 @@ func (c *ovndb) MonitorTables(jsonContext interface{}) (*libovsdb.TableUpdates,
return c.client.Monitor(c.db, jsonContext, requests)
}

// TODO return proper error
func (c *ovndb) Close() error {
func (c *ovndb) close() error {
c.client.Disconnect()
return nil
}

// TODO return proper error
func (c *ovndb) Close() error {
c.tranmutex.Lock()
defer c.tranmutex.Unlock()
return c.close()
}

func (c *ovndb) getSchema(db string) libovsdb.DatabaseSchema {
return c.client.Schema[db]
}

func (c *ovndb) GetSchema() libovsdb.DatabaseSchema {
c.tranmutex.RLock()
defer c.tranmutex.RUnlock()
return c.client.Schema[c.db]
}

Expand Down
5 changes: 4 additions & 1 deletion ovnimp.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func (odbi *ovndb) getRowsMatchingUUID(table, field, uuid string) ([]string, err
}

func (odbi *ovndb) transact(db string, ops ...libovsdb.Operation) ([]libovsdb.OperationResult, error) {
odbi.tranmutex.RLock()
defer odbi.tranmutex.RUnlock()
reply, err := odbi.client.Transact(db, ops...)

if err != nil {
Expand All @@ -164,7 +166,8 @@ func (odbi *ovndb) transact(db string, ops ...libovsdb.Operation) ([]libovsdb.Op
if i < len(ops) {
opsInfo = fmt.Sprintf("%v", ops[i])
}
return nil, fmt.Errorf("Transaction Failed due to an error: %v details: %v in %s",
odbi.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't trigger reconnect if odbi.reconn is not true.

return nil, fmt.Errorf("Reconnecting...Transaction Failed due to an error: %v details: %v in %s",
o.Error, o.Details, opsInfo)
}
}
Expand Down