|
@@ -116,8 +116,6 @@ func migrateEntries(serverEntries []*ServerEntry, legacyDataStoreFilename string
|
|
|
// legacyServerEntryIterator is used to iterate over
|
|
// legacyServerEntryIterator is used to iterate over
|
|
|
// stored server entries in rank order.
|
|
// stored server entries in rank order.
|
|
|
type legacyServerEntryIterator struct {
|
|
type legacyServerEntryIterator struct {
|
|
|
- region string
|
|
|
|
|
- protocol string
|
|
|
|
|
shuffleHeadLength int
|
|
shuffleHeadLength int
|
|
|
transaction *sql.Tx
|
|
transaction *sql.Tx
|
|
|
cursor *sql.Rows
|
|
cursor *sql.Rows
|
|
@@ -127,8 +125,6 @@ type legacyServerEntryIterator struct {
|
|
|
func newlegacyServerEntryIterator(config *Config) (iterator *legacyServerEntryIterator, err error) {
|
|
func newlegacyServerEntryIterator(config *Config) (iterator *legacyServerEntryIterator, err error) {
|
|
|
|
|
|
|
|
iterator = &legacyServerEntryIterator{
|
|
iterator = &legacyServerEntryIterator{
|
|
|
- region: config.EgressRegion,
|
|
|
|
|
- protocol: config.TunnelProtocol,
|
|
|
|
|
shuffleHeadLength: config.TunnelPoolSize,
|
|
shuffleHeadLength: config.TunnelPoolSize,
|
|
|
}
|
|
}
|
|
|
err = iterator.Reset()
|
|
err = iterator.Reset()
|
|
@@ -187,9 +183,6 @@ func (iterator *legacyServerEntryIterator) Next() (serverEntry *ServerEntry, err
|
|
|
func (iterator *legacyServerEntryIterator) Reset() error {
|
|
func (iterator *legacyServerEntryIterator) Reset() error {
|
|
|
iterator.Close()
|
|
iterator.Close()
|
|
|
|
|
|
|
|
- count := countLegacyServerEntries(iterator.region, iterator.protocol)
|
|
|
|
|
- NoticeCandidateServers(iterator.region, iterator.protocol, count)
|
|
|
|
|
-
|
|
|
|
|
transaction, err := legacyDb.Begin()
|
|
transaction, err := legacyDb.Begin()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return ContextError(err)
|
|
return ContextError(err)
|
|
@@ -201,8 +194,7 @@ func (iterator *legacyServerEntryIterator) Reset() error {
|
|
|
// (priority) order, to favor previously successful servers; then the
|
|
// (priority) order, to favor previously successful servers; then the
|
|
|
// remaining long tail is shuffled to raise up less recent candidates.
|
|
// remaining long tail is shuffled to raise up less recent candidates.
|
|
|
|
|
|
|
|
- whereClause, whereParams := makeServerEntryWhereClause(
|
|
|
|
|
- iterator.region, iterator.protocol, nil)
|
|
|
|
|
|
|
+ whereClause, whereParams := makeServerEntryWhereClause(nil)
|
|
|
headLength := iterator.shuffleHeadLength
|
|
headLength := iterator.shuffleHeadLength
|
|
|
queryFormat := `
|
|
queryFormat := `
|
|
|
select data from serverEntry %s
|
|
select data from serverEntry %s
|
|
@@ -228,24 +220,9 @@ func (iterator *legacyServerEntryIterator) Reset() error {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func makeServerEntryWhereClause(
|
|
|
|
|
- region, protocol string, excludeIds []string) (whereClause string, whereParams []interface{}) {
|
|
|
|
|
|
|
+func makeServerEntryWhereClause(excludeIds []string) (whereClause string, whereParams []interface{}) {
|
|
|
whereClause = ""
|
|
whereClause = ""
|
|
|
whereParams = make([]interface{}, 0)
|
|
whereParams = make([]interface{}, 0)
|
|
|
- if region != "" {
|
|
|
|
|
- whereClause += " where region = ?"
|
|
|
|
|
- whereParams = append(whereParams, region)
|
|
|
|
|
- }
|
|
|
|
|
- if protocol != "" {
|
|
|
|
|
- if len(whereClause) > 0 {
|
|
|
|
|
- whereClause += " and"
|
|
|
|
|
- } else {
|
|
|
|
|
- whereClause += " where"
|
|
|
|
|
- }
|
|
|
|
|
- whereClause +=
|
|
|
|
|
- " exists (select 1 from serverEntryProtocol where protocol = ? and serverEntryId = serverEntry.id)"
|
|
|
|
|
- whereParams = append(whereParams, protocol)
|
|
|
|
|
- }
|
|
|
|
|
if len(excludeIds) > 0 {
|
|
if len(excludeIds) > 0 {
|
|
|
if len(whereClause) > 0 {
|
|
if len(whereClause) > 0 {
|
|
|
whereClause += " and"
|
|
whereClause += " and"
|
|
@@ -264,27 +241,3 @@ func makeServerEntryWhereClause(
|
|
|
}
|
|
}
|
|
|
return whereClause, whereParams
|
|
return whereClause, whereParams
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-// countLegacyServerEntries returns a count of stored servers for the specified region and protocol.
|
|
|
|
|
-func countLegacyServerEntries(region, protocol string) int {
|
|
|
|
|
- var count int
|
|
|
|
|
- whereClause, whereParams := makeServerEntryWhereClause(region, protocol, nil)
|
|
|
|
|
- query := "select count(*) from serverEntry" + whereClause
|
|
|
|
|
- err := legacyDb.QueryRow(query, whereParams...).Scan(&count)
|
|
|
|
|
-
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- NoticeAlert("countLegacyServerEntries failed: %s", err)
|
|
|
|
|
- return 0
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if region == "" {
|
|
|
|
|
- region = "(any)"
|
|
|
|
|
- }
|
|
|
|
|
- if protocol == "" {
|
|
|
|
|
- protocol = "(any)"
|
|
|
|
|
- }
|
|
|
|
|
- NoticeInfo("servers for region %s and protocol %s: %d",
|
|
|
|
|
- region, protocol, count)
|
|
|
|
|
-
|
|
|
|
|
- return count
|
|
|
|
|
-}
|
|
|