@@ -2261,17 +2261,28 @@ func deleteDatabaseHandler(w http.ResponseWriter, r *http.Request) {
2261
2261
return
2262
2262
}
2263
2263
2264
- // Invalidate the memcache data for the database, so the new branch count gets picked up
2265
- // Note - on one hand this is a race condition, as new cache data could get into memcache between this invalidation
2266
- // call and the delete. On the other hand, once it's deleted the invalidation function would itself fail due to
2267
- // needing the database to be present so it can look up the commit list. At least doing the invalidation here lets
2268
- // us clear stale data (hopefully) for the vast majority of the time
2269
- err = com .InvalidateCacheEntry (loggedInUser , dbOwner , dbFolder , dbName , "" ) // Empty string indicates "for all versions"
2264
+ // If this is a standard database, then invalidate it's memcache data
2265
+ var isLive bool
2266
+ var liveNode string
2267
+ isLive , liveNode , err = com .CheckDBLive (dbOwner , dbFolder , dbName )
2270
2268
if err != nil {
2271
- // Something went wrong when invalidating memcached entries for the database
2272
- log . Printf ( "Error when invalidating memcache entries: %s \n " , err . Error () )
2269
+ w . WriteHeader ( http . StatusInternalServerError )
2270
+ fmt . Fprint ( w , "Internal server error" )
2273
2271
return
2274
2272
}
2273
+ if ! isLive {
2274
+ // Invalidate the memcache data for the database, so the new branch count gets picked up
2275
+ // Note - on one hand this is a race condition, as new cache data could get into memcache between this invalidation
2276
+ // call and the delete. On the other hand, once it's deleted the invalidation function would itself fail due to
2277
+ // needing the database to be present so it can look up the commit list. At least doing the invalidation here lets
2278
+ // us clear stale data (hopefully) for the vast majority of the time
2279
+ err = com .InvalidateCacheEntry (loggedInUser , dbOwner , dbFolder , dbName , "" ) // Empty string indicates "for all versions"
2280
+ if err != nil {
2281
+ // Something went wrong when invalidating memcached entries for the database
2282
+ log .Printf ("Error when invalidating memcache entries: %s\n " , err .Error ())
2283
+ return
2284
+ }
2285
+ }
2275
2286
2276
2287
// Delete the database
2277
2288
err = com .DeleteDatabase (dbOwner , dbFolder , dbName )
@@ -2281,6 +2292,53 @@ func deleteDatabaseHandler(w http.ResponseWriter, r *http.Request) {
2281
2292
return
2282
2293
}
2283
2294
2295
+ // For a live database, delete it from both Minio and our AMQP backend
2296
+ // FIXME: This code to delete the live database from the AMQP backend was directly copied from
2297
+ // FIXME api/main.go. Move the code into a shared function at some point
2298
+ if isLive {
2299
+ // Delete the database from Minio
2300
+ bucket := fmt .Sprintf ("live-%s" , dbOwner )
2301
+ id := dbName
2302
+ err = com .MinioDeleteDatabase ("webUI" , dbOwner , dbName , bucket , id )
2303
+ if err != nil {
2304
+ w .WriteHeader (http .StatusInternalServerError )
2305
+ fmt .Fprint (w , "Internal server error" )
2306
+ log .Println (err )
2307
+ return
2308
+ }
2309
+
2310
+ // Delete the database from our AMQP backend
2311
+ var rawResponse []byte
2312
+ rawResponse , err = com .MQRequest (com .AmqpChan , liveNode , "delete" , loggedInUser , dbOwner , dbName , "" )
2313
+ if err != nil {
2314
+ w .WriteHeader (http .StatusInternalServerError )
2315
+ fmt .Fprint (w , "Internal server error" )
2316
+ log .Println (err )
2317
+ return
2318
+ }
2319
+
2320
+ // Decode the response
2321
+ var resp com.LiveDBErrorResponse
2322
+ err = json .Unmarshal (rawResponse , & resp )
2323
+ if err != nil {
2324
+ w .WriteHeader (http .StatusInternalServerError )
2325
+ fmt .Fprint (w , "Internal server error" )
2326
+ log .Println (err )
2327
+ return
2328
+ }
2329
+ if resp .Error != "" {
2330
+ err = errors .New (resp .Error )
2331
+ w .WriteHeader (http .StatusInternalServerError )
2332
+ fmt .Fprint (w , "Internal server error" )
2333
+ log .Println (err )
2334
+ return
2335
+ }
2336
+ if resp .Node == "" {
2337
+ log .Printf ("In webUI (Live) deleteDatabaseHandler(). A node responded, but didn't identify itself." )
2338
+ return
2339
+ }
2340
+ }
2341
+
2284
2342
// Update succeeded
2285
2343
w .WriteHeader (http .StatusOK )
2286
2344
}
0 commit comments