66 "path/filepath"
77 "strings"
88
9- "github.com/gluster/glusterd2/glusterd2/daemon "
9+ "github.com/gluster/glusterd2/glusterd2/events "
1010 "github.com/gluster/glusterd2/glusterd2/gdctx"
1111 restutils "github.com/gluster/glusterd2/glusterd2/servers/rest/utils"
1212 "github.com/gluster/glusterd2/glusterd2/transaction"
@@ -26,23 +26,6 @@ func registerVolShrinkStepFuncs() {
2626 transaction .RegisterStepFunc (startRebalance , "vol-shrink.StartRebalance" )
2727}
2828
29- func startRebalance (c transaction.TxnCtx ) error {
30- var rinfo rebalanceapi.RebalInfo
31- err := c .Get ("rinfo" , & rinfo )
32- if err != nil {
33- return err
34- }
35-
36- rebalanceProcess , err := rebalance .NewRebalanceProcess (rinfo )
37- if err != nil {
38- return err
39- }
40-
41- err = daemon .Start (rebalanceProcess , true )
42-
43- return err
44- }
45-
4629func validateVolumeShrinkReq (req api.VolShrinkReq ) error {
4730 dupEntry := map [string ]bool {}
4831
@@ -100,7 +83,7 @@ func volumeShrinkHandler(w http.ResponseWriter, r *http.Request) {
10083 }
10184 }
10285 if ! isPresent {
103- restutils .SendHTTPError (ctx , w , http .StatusBadRequest , "One or more brick is not part of given volume" )
86+ restutils .SendHTTPError (ctx , w , http .StatusBadRequest , "One or more bricks is not part of given volume" )
10487 return
10588 }
10689 }
@@ -148,19 +131,20 @@ func volumeShrinkHandler(w http.ResponseWriter, r *http.Request) {
148131 if err != nil {
149132 restutils .SendHTTPError (ctx , w , http .StatusInternalServerError , err )
150133 return
151-
152134 }
153135
154- // The following line is for testing purposes.
155- // It seems that there is no other way to include this information in the rebalance volfile right now.
136+ // TODO: Find a better wat to store information in the rebalance volfile.
156137 volinfo .Options ["distribute.decommissioned-bricks" ] = strings .TrimSpace (decommissionedSubvols )
157138
158- var rinfo rebalanceapi.RebalInfo
159- rinfo .Volname = volname
160- rinfo .RebalanceID = uuid .NewRandom ()
161- rinfo .Cmd = rebalanceapi .CmdStartForce
162- rinfo .State = rebalanceapi .NotStarted
163- rinfo .CommitHash = rebalance .SetCommitHash ()
139+ rinfo := rebalanceapi.RebalInfo {
140+ Volname : volname ,
141+ RebalanceID : uuid .NewRandom (),
142+ Cmd : rebalanceapi .CmdStartForce ,
143+ State : rebalanceapi .NotStarted ,
144+ CommitHash : rebalance .SetCommitHash (),
145+ RebalStats : []rebalanceapi.RebalNodeStatus {},
146+ }
147+
164148 if err := txn .Ctx .Set ("rinfo" , rinfo ); err != nil {
165149 restutils .SendHTTPError (ctx , w , http .StatusInternalServerError , err )
166150 return
@@ -173,19 +157,18 @@ func volumeShrinkHandler(w http.ResponseWriter, r *http.Request) {
173157
174158 if err = txn .Do (); err != nil {
175159 logger .WithError (err ).Error ("remove bricks start transaction failed" )
176- if err == transaction .ErrLockTimeout {
177- restutils .SendHTTPError (ctx , w , http .StatusConflict , err )
178- } else {
179- restutils .SendHTTPError (ctx , w , http .StatusInternalServerError , err )
180- }
160+ status , err := restutils .ErrToStatusCode (err )
161+ restutils .SendHTTPError (ctx , w , status , err )
181162 return
182163 }
183-
164+ logger .WithField ("volume-name" , volinfo .Name ).Info ("volume shrink successful" )
165+ events .Broadcast (volume .NewEvent (volume .EventVolumeShrink , volinfo ))
184166 restutils .SendHTTPResponse (ctx , w , http .StatusOK , decommissionedSubvols )
185167
186168}
187169
188170func findDecommissioned (bricks []api.BrickReq , volinfo * volume.Volinfo ) (string , error ) {
171+
189172 brickSet := make (map [string ]bool )
190173 for _ , brick := range bricks {
191174 u := uuid .Parse (brick .PeerID )
@@ -209,7 +192,6 @@ func findDecommissioned(bricks []api.BrickReq, volinfo *volume.Volinfo) (string,
209192 subvolMap [subvol .Name ] = count + 1
210193 }
211194 }
212-
213195 }
214196 }
215197
0 commit comments