@@ -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 {
122123session ,err := c .provision .StartSession (w .username ,w .password ,w .snapshot .ID )
123124if err != nil {
124125// TODO(anatoly): Empty room case.
126+ log .Errf ("Failed to create a clone: %+v." ,err )
127+
125128if err := c .updateCloneStatus (cloneID , models.Status {
126129Code :models .StatusFatal ,
127130Message :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
132135return
@@ -193,15 +196,15 @@ func (c *baseCloning) DestroyClone(cloneID string) error {
193196
194197go func () {
195198if err := c .provision .StopSession (w .session );err != nil {
199+ log .Errf ("Failed to delete a clone: %+v." ,err )
200+
196201if err := c .updateCloneStatus (cloneID , models.Status {
197202Code :models .StatusFatal ,
198203Message :models .CloneMessageFatal ,
199204});err != nil {
200205log .Errf ("Failed to update clone status: %v" ,err )
201206}
202207
203- log .Errf ("Failed to delete clone: %+v." ,err )
204-
205208return
206209}
207210
@@ -304,15 +307,15 @@ func (c *baseCloning) ResetClone(cloneID string) error {
304307go func () {
305308err := c .provision .ResetSession (w .session ,w .snapshot .ID )
306309if err != nil {
310+ log .Errf ("Failed to reset a clone: %+v." ,err )
311+
307312if err := c .updateCloneStatus (cloneID , models.Status {
308313Code :models .StatusFatal ,
309314Message :models .CloneMessageFatal ,
310315});err != nil {
311316log .Errf ("failed to update clone status: %v" ,err )
312317}
313318
314- log .Errf ("Failed to reset session: %+v." ,err )
315-
316319return
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 ) {
545548log .Dbg (fmt .Sprintf ("Check an active query for: %q." ,session .ID ))
546549
547550db ,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 {
564567return 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) {
569572var isRunningQueryNotExists bool
570573
571574query := `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)`
575578err := db .QueryRow (query ).Scan (& isRunningQueryNotExists )
576579