Skip to content

Commit

Permalink
Fix the node discovery bug (See #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
superkkt committed Apr 21, 2018
1 parent 86b8d56 commit 4767d4c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ import (
"math"
"math/rand"
"net"
"runtime"
"strings"
"time"
"runtime"

"github.com/superkkt/cherry/network"
"github.com/superkkt/cherry/northbound/app/discovery"
"github.com/superkkt/cherry/northbound/app/proxyarp"
"github.com/superkkt/cherry/northbound/app/virtualip"

"github.com/go-sql-driver/mysql"
"github.com/superkkt/viper"
"github.com/superkkt/go-logging"
"github.com/superkkt/viper"
)

const (
maxDeadlockRetry = 5
maxDeadlockRetry = 5

deadlockErrCode uint16 = 1213
foreignkeyErrCode uint16 = 1451
Expand All @@ -53,7 +53,7 @@ const (
)

var (
logger = logging.MustGetLogger("database")
logger = logging.MustGetLogger("database")

maxIdleConn = runtime.NumCPU()
maxOpenConn = maxIdleConn * 2
Expand Down Expand Up @@ -87,7 +87,7 @@ func NewMySQL() (*MySQL, error) {
}

return &MySQL{
db: db,
db: db,
random: rand.New(&randomSource{src: rand.NewSource(time.Now().Unix())}),
}, nil
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func (r *MySQL) Location(mac net.HardwareAddr) (dpid string, port uint32, status
status = network.LocationUnregistered

var portID sql.NullInt64
qry := "SELECT `port_id` FROM `host` WHERE `mac` = ? LOCK IN SHARE MODE"
qry := "SELECT `port_id` FROM `host` WHERE `mac` = ? ORDER BY `port_id` DESC LOCK IN SHARE MODE"
if err := tx.QueryRow(qry, []byte(mac)).Scan(&portID); err != nil {
// Unregistered host?
if err == sql.ErrNoRows {
Expand Down

0 comments on commit 4767d4c

Please sign in to comment.