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

Reduce memory usage by fixing alignment of fields in structs #167

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ linters-settings:
- name: empty-block
- name: unreachable-code
- name: redefines-builtin-id
govet:
Copy link
Collaborator

Choose a reason for hiding this comment

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

After merging the PR, we will lose the ability to rearrange fields in structures :(
In my opinion, it is not good for readability.

enable:
- fieldalignment

linters:
disable-all: true
Expand Down
20 changes: 10 additions & 10 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ import (

// App is main application structure
type App struct {
state appState
logger *log.Logger
config *config.Config
lostQuorumTime time.Time
externalReplication mysql.IExternalReplication
switchHelper mysql.ISwitchHelper
dcs dcs.DCS
cluster *mysql.Cluster
filelock *flock.Flock
nodeFailedAt map[string]time.Time
filelock *flock.Flock
slaveReadPositions map[string]string
streamFromFailedAt map[string]time.Time
daemonState *DaemonState
daemonMutex sync.Mutex
replRepairState map[string]*ReplicationRepairState
externalReplication mysql.IExternalReplication
switchHelper mysql.ISwitchHelper
lostQuorumTime time.Time
cluster *mysql.Cluster
config *config.Config
logger *log.Logger
state appState
daemonMutex sync.Mutex
}

// NewApp returns new App. Suddenly.
Expand Down Expand Up @@ -2458,7 +2458,7 @@ func (app *App) getNodePositions(activeNodes []string) ([]nodePosition, error) {
}

positionsMutex.Lock()
positions = append(positions, nodePosition{host, gtidset, *lag, nc.Priority})
positions = append(positions, nodePosition{gtidset, host, *lag, nc.Priority})
positionsMutex.Unlock()
return nil
}, activeNodes)
Expand Down
41 changes: 20 additions & 21 deletions internal/app/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,24 @@ var (

// NodeState contains status check performed by some mysync process
type NodeState struct {
CheckBy string `json:"check_by"`
CheckAt time.Time `json:"check_at"`
PingOk bool `json:"ping_ok"`
PingDubious bool `json:"ping_dubious"`
SemiSyncState *SemiSyncState `json:"semi_sync_state"`
SlaveState *SlaveState `json:"slave_state"`
MasterState *MasterState `json:"master_state"`
DaemonState *DaemonState `json:"daemon_state"`
DiskState *DiskState `json:"disk_state"`
Error string `json:"error"`
CheckBy string `json:"check_by"`
IsMaster bool `json:"is_master"`
IsReadOnly bool `json:"is_readonly"`
IsSuperReadOnly bool `json:"is_super_readonly"`
IsOffline bool `json:"is_offline"`
IsCascade bool `json:"is_cascade"`
IsFileSystemReadonly bool `json:"is_file_system_readonly"`
IsLoadingBinlog bool `json:"is_loading_binlog"`
Error string `json:"error"`
DiskState *DiskState `json:"disk_state"`
DaemonState *DaemonState `json:"daemon_state"`
MasterState *MasterState `json:"master_state"`
SlaveState *SlaveState `json:"slave_state"`
SemiSyncState *SemiSyncState `json:"semi_sync_state"`

ShowOnlyGTIDDiff bool
IsCascade bool `json:"is_cascade"`
IsOffline bool `json:"is_offline"`
IsSuperReadOnly bool `json:"is_super_readonly"`
IsReadOnly bool `json:"is_readonly"`
PingDubious bool `json:"ping_dubious"`
PingOk bool `json:"ping_ok"`
ShowOnlyGTIDDiff bool
}

// Last_SQL_Errno codes, that disallow to restart replication
Expand Down Expand Up @@ -300,14 +299,14 @@ const (

// Switchover contains info about currently running or scheduled switchover/failover process
type Switchover struct {
InitiatedAt time.Time `json:"initiated_at"`
StartedAt time.Time `json:"started_at"`
Result *SwitchoverResult `json:"result"`
From string `json:"from"`
To string `json:"to"`
Cause string `json:"cause"`
InitiatedBy string `json:"initiated_by"`
InitiatedAt time.Time `json:"initiated_at"`
StartedBy string `json:"started_by"`
StartedAt time.Time `json:"started_at"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure that we would like to split fields with the same prefix.

Result *SwitchoverResult `json:"result"`
RunCount int `json:"run_count,omitempty"`
}

Expand Down Expand Up @@ -337,15 +336,15 @@ func (sw *Switchover) String() string {

// SwitchoverResult contains results of finished/failed switchover
type SwitchoverResult struct {
Ok bool `json:"ok"`
Error string `json:"error"`
FinishedAt time.Time `json:"finished_at"`
Error string `json:"error"`
Ok bool `json:"ok"`
}

// Maintenance struct presence means that cluster under manual control
type Maintenance struct {
InitiatedBy string `json:"initiated_by"`
InitiatedAt time.Time `json:"initiated_at"`
InitiatedBy string `json:"initiated_by"`
MySyncPaused bool `json:"mysync_paused"`
ShouldLeave bool `json:"should_leave"`
}
Expand Down
8 changes: 4 additions & 4 deletions internal/app/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

type nodePosition struct {
host string
gtidset gtids.GTIDSet
host string
lag float64
priority int64
}
Expand Down Expand Up @@ -194,15 +194,15 @@ func getDubiousHAHosts(clusterState map[string]*NodeState) []string {

func getNodeStatesInParallel(hosts []string, getter func(string) (*NodeState, error), logger *log.Logger) (map[string]*NodeState, error) {
type result struct {
name string
state *NodeState
err error
state *NodeState
name string
}
results := make(chan result, len(hosts))
for _, host := range hosts {
go func(host string) {
state, err := getter(host)
results <- result{host, state, err}
results <- result{err, state, host}
}(host)
}
clusterState := make(map[string]*NodeState)
Expand Down
Loading
Loading