@@ -86,23 +86,24 @@ func (s *ClusterSchemer) createTablesSQLs(
8686 replicatedCreateSQLs []string ,
8787 distributedObjectNames []string ,
8888 distributedCreateSQLs []string ,
89+ err error ,
8990) {
90- if names , sql , err : = s .getReplicatedObjectsSQLs (ctx , host ); err == nil {
91- replicatedObjectNames = names
92- replicatedCreateSQLs = sql
91+ replicatedObjectNames , replicatedCreateSQLs , err = s .getReplicatedObjectsSQLs (ctx , host )
92+ if err != nil {
93+ return nil , nil , nil , nil , err
9394 }
94- if names , sql , err : = s .getDistributedObjectsSQLs (ctx , host ); err == nil {
95- distributedObjectNames = names
96- distributedCreateSQLs = sql
95+ distributedObjectNames , distributedCreateSQLs , err = s .getDistributedObjectsSQLs (ctx , host )
96+ if err != nil {
97+ return nil , nil , nil , nil , err
9798 }
98- return
99+ return replicatedObjectNames , replicatedCreateSQLs , distributedObjectNames , distributedCreateSQLs , nil
99100}
100101
101102// HostCreateTables creates tables on a new host
102103func (s * ClusterSchemer ) HostCreateTables (ctx context.Context , host * api.Host ) error {
103104 if util .IsContextDone (ctx ) {
104105 log .V (1 ).Info ("ctx is done" )
105- return nil
106+ return ctx . Err ()
106107 }
107108
108109 log .V (1 ).M (host ).F ().S ().Info ("Migrating schema objects to host %s" , host .Runtime .Address .HostName )
@@ -111,29 +112,29 @@ func (s *ClusterSchemer) HostCreateTables(ctx context.Context, host *api.Host) e
111112 replicatedObjectNames ,
112113 replicatedCreateSQLs ,
113114 distributedObjectNames ,
114- distributedCreateSQLs := s .createTablesSQLs (ctx , host )
115+ distributedCreateSQLs ,
116+ err := s .createTablesSQLs (ctx , host )
117+ if err != nil {
118+ log .V (1 ).M (host ).F ().Error ("Failed to discover schema objects for host %s: %v" , host .Runtime .Address .HostName , err )
119+ return err
120+ }
115121
116- var err1 error
117122 if len (replicatedCreateSQLs ) > 0 {
118123 log .V (1 ).M (host ).F ().Info ("Creating replicated objects at %s: %v" , host .Runtime .Address .HostName , replicatedObjectNames )
119124 log .V (2 ).M (host ).F ().Info ("\n %v" , replicatedCreateSQLs )
120- err1 = s .ExecHost (ctx , host , replicatedCreateSQLs ,
121- clickhouse .NewQueryOptions ().SetRetry (true ).SetLogQueries (true ))
125+ if err := s .ExecHost (ctx , host , replicatedCreateSQLs ,
126+ clickhouse .NewQueryOptions ().SetRetry (true ).SetLogQueries (true )); err != nil {
127+ return err
128+ }
122129 }
123130
124- var err2 error
125131 if len (distributedCreateSQLs ) > 0 {
126132 log .V (1 ).M (host ).F ().Info ("Creating distributed objects at %s: %v" , host .Runtime .Address .HostName , distributedObjectNames )
127133 log .V (2 ).M (host ).F ().Info ("\n %v" , distributedCreateSQLs )
128- err2 = s .ExecHost (ctx , host , distributedCreateSQLs ,
129- clickhouse .NewQueryOptions ().SetRetry (true ).SetLogQueries (true ))
130- }
131-
132- if err2 != nil {
133- return err2
134- }
135- if err1 != nil {
136- return err1
134+ if err := s .ExecHost (ctx , host , distributedCreateSQLs ,
135+ clickhouse .NewQueryOptions ().SetRetry (true ).SetLogQueries (true )); err != nil {
136+ return err
137+ }
137138 }
138139
139140 return nil
0 commit comments