@@ -20,6 +20,7 @@ import (
2020 "gitlab.com/postgres-ai/database-lab/pkg/log"
2121 "gitlab.com/postgres-ai/database-lab/pkg/models"
2222 "gitlab.com/postgres-ai/database-lab/pkg/services/provision"
23+ "gitlab.com/postgres-ai/database-lab/pkg/services/provision/resources"
2324 "gitlab.com/postgres-ai/database-lab/pkg/util"
2425 "gitlab.com/postgres-ai/database-lab/pkg/util/pglog"
2526)
@@ -122,11 +123,13 @@ func (c *baseCloning) CreateClone(clone *models.Clone) error {
122123 session , err := c .provision .StartSession (w .username , w .password , w .snapshot .ID )
123124 if err != nil {
124125 // TODO(anatoly): Empty room case.
126+ log .Errf ("Failed to create a clone: %+v." , err )
127+
125128 if err := c .updateCloneStatus (cloneID , models.Status {
126129 Code : models .StatusFatal ,
127130 Message : models .CloneMessageFatal ,
128131 }); err != nil {
129- log .Errf ("failed to update clone status: %v" , err )
132+ log .Errf ("Failed to update clone status: %v" , err )
130133 }
131134
132135 return
@@ -193,15 +196,15 @@ func (c *baseCloning) DestroyClone(cloneID string) error {
193196
194197 go func () {
195198 if err := c .provision .StopSession (w .session ); err != nil {
199+ log .Errf ("Failed to delete a clone: %+v." , err )
200+
196201 if err := c .updateCloneStatus (cloneID , models.Status {
197202 Code : models .StatusFatal ,
198203 Message : models .CloneMessageFatal ,
199204 }); err != nil {
200205 log .Errf ("Failed to update clone status: %v" , err )
201206 }
202207
203- log .Errf ("Failed to delete clone: %+v." , err )
204-
205208 return
206209 }
207210
@@ -304,15 +307,15 @@ func (c *baseCloning) ResetClone(cloneID string) error {
304307 go func () {
305308 err := c .provision .ResetSession (w .session , w .snapshot .ID )
306309 if err != nil {
310+ log .Errf ("Failed to reset a clone: %+v." , err )
311+
307312 if err := c .updateCloneStatus (cloneID , models.Status {
308313 Code : models .StatusFatal ,
309314 Message : models .CloneMessageFatal ,
310315 }); err != nil {
311316 log .Errf ("failed to update clone status: %v" , err )
312317 }
313318
314- log .Errf ("Failed to reset session: %+v." , err )
315-
316319 return
317320 }
318321
@@ -541,7 +544,7 @@ func (c *baseCloning) isIdleClone(wrapper *CloneWrapper) (bool, error) {
541544const pgDriverName = "postgres"
542545
543546// hasNotQueryActivity opens connection and checks if there is no any query running by a user.
544- func hasNotQueryActivity (session * provision .Session ) (bool , error ) {
547+ func hasNotQueryActivity (session * resources .Session ) (bool , error ) {
545548 log .Dbg (fmt .Sprintf ("Check an active query for: %q." , session .ID ))
546549
547550 db , err := sql .Open (pgDriverName , getSocketConnStr (session ))
@@ -560,7 +563,7 @@ func hasNotQueryActivity(session *provision.Session) (bool, error) {
560563}
561564
562565// TODO(akartasov): Move the function to the provision service.
563- func getSocketConnStr (session * provision .Session ) string {
566+ func getSocketConnStr (session * resources .Session ) string {
564567 return fmt .Sprintf ("host=%s user=%s dbname=postgres" , session .SocketHost , session .User )
565568}
566569
@@ -569,8 +572,8 @@ func checkActiveQueryNotExists(db *sql.DB) (bool, error) {
569572 var isRunningQueryNotExists bool
570573
571574 query := `select not exists (
572- select * from pg_stat_activity
573- where state <> 'idle' and query not like 'autovacuum: %' and pid <> pg_backend_pid()
575+ select * from pg_stat_activity
576+ where state <> 'idle' and query not like 'autovacuum: %' and pid <> pg_backend_pid()
574577 )`
575578 err := db .QueryRow (query ).Scan (& isRunningQueryNotExists )
576579
0 commit comments