@@ -20,6 +20,7 @@ import (
20
20
"gitlab.com/postgres-ai/database-lab/pkg/log"
21
21
"gitlab.com/postgres-ai/database-lab/pkg/models"
22
22
"gitlab.com/postgres-ai/database-lab/pkg/services/provision"
23
+ "gitlab.com/postgres-ai/database-lab/pkg/services/provision/resources"
23
24
"gitlab.com/postgres-ai/database-lab/pkg/util"
24
25
"gitlab.com/postgres-ai/database-lab/pkg/util/pglog"
25
26
)
@@ -122,11 +123,13 @@ func (c *baseCloning) CreateClone(clone *models.Clone) error {
122
123
session , err := c .provision .StartSession (w .username , w .password , w .snapshot .ID )
123
124
if err != nil {
124
125
// TODO(anatoly): Empty room case.
126
+ log .Errf ("Failed to create a clone: %+v." , err )
127
+
125
128
if err := c .updateCloneStatus (cloneID , models.Status {
126
129
Code : models .StatusFatal ,
127
130
Message : models .CloneMessageFatal ,
128
131
}); err != nil {
129
- log .Errf ("failed to update clone status: %v" , err )
132
+ log .Errf ("Failed to update clone status: %v" , err )
130
133
}
131
134
132
135
return
@@ -193,15 +196,15 @@ func (c *baseCloning) DestroyClone(cloneID string) error {
193
196
194
197
go func () {
195
198
if err := c .provision .StopSession (w .session ); err != nil {
199
+ log .Errf ("Failed to delete a clone: %+v." , err )
200
+
196
201
if err := c .updateCloneStatus (cloneID , models.Status {
197
202
Code : models .StatusFatal ,
198
203
Message : models .CloneMessageFatal ,
199
204
}); err != nil {
200
205
log .Errf ("Failed to update clone status: %v" , err )
201
206
}
202
207
203
- log .Errf ("Failed to delete clone: %+v." , err )
204
-
205
208
return
206
209
}
207
210
@@ -304,15 +307,15 @@ func (c *baseCloning) ResetClone(cloneID string) error {
304
307
go func () {
305
308
err := c .provision .ResetSession (w .session , w .snapshot .ID )
306
309
if err != nil {
310
+ log .Errf ("Failed to reset a clone: %+v." , err )
311
+
307
312
if err := c .updateCloneStatus (cloneID , models.Status {
308
313
Code : models .StatusFatal ,
309
314
Message : models .CloneMessageFatal ,
310
315
}); err != nil {
311
316
log .Errf ("failed to update clone status: %v" , err )
312
317
}
313
318
314
- log .Errf ("Failed to reset session: %+v." , err )
315
-
316
319
return
317
320
}
318
321
@@ -541,7 +544,7 @@ func (c *baseCloning) isIdleClone(wrapper *CloneWrapper) (bool, error) {
541
544
const pgDriverName = "postgres"
542
545
543
546
// 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 ) {
545
548
log .Dbg (fmt .Sprintf ("Check an active query for: %q." , session .ID ))
546
549
547
550
db , err := sql .Open (pgDriverName , getSocketConnStr (session ))
@@ -560,7 +563,7 @@ func hasNotQueryActivity(session *provision.Session) (bool, error) {
560
563
}
561
564
562
565
// TODO(akartasov): Move the function to the provision service.
563
- func getSocketConnStr (session * provision .Session ) string {
566
+ func getSocketConnStr (session * resources .Session ) string {
564
567
return fmt .Sprintf ("host=%s user=%s dbname=postgres" , session .SocketHost , session .User )
565
568
}
566
569
@@ -569,8 +572,8 @@ func checkActiveQueryNotExists(db *sql.DB) (bool, error) {
569
572
var isRunningQueryNotExists bool
570
573
571
574
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()
574
577
)`
575
578
err := db .QueryRow (query ).Scan (& isRunningQueryNotExists )
576
579
0 commit comments