@@ -1274,19 +1274,26 @@ write_large_message(MsgId, MsgBodyBin,
1274
1274
ok = index_insert (IndexEts ,
1275
1275
# msg_location { msg_id = MsgId , ref_count = 1 , file = LargeMsgFile ,
1276
1276
offset = 0 , total_size = TotalSize }),
1277
- _ = case CurFile of
1277
+ State1 = case CurFile of
1278
1278
% % We didn't open a new file. We must update the existing value.
1279
1279
LargeMsgFile ->
1280
1280
[_ ,_ ] = ets :update_counter (FileSummaryEts , LargeMsgFile ,
1281
1281
[{# file_summary .valid_total_size , TotalSize },
1282
- {# file_summary .file_size , TotalSize }]);
1282
+ {# file_summary .file_size , TotalSize }]),
1283
+ State0 ;
1283
1284
% % We opened a new file. We can insert it all at once.
1285
+ % % We must also check whether we need to delete the previous
1286
+ % % current file, because if there is no valid data this is
1287
+ % % the only time we will consider it (outside recovery).
1284
1288
_ ->
1285
1289
true = ets :insert_new (FileSummaryEts , # file_summary {
1286
1290
file = LargeMsgFile ,
1287
1291
valid_total_size = TotalSize ,
1288
1292
file_size = TotalSize ,
1289
- locked = false })
1293
+ locked = false }),
1294
+ delete_file_if_empty (CurFile , State0 # msstate { current_file_handle = LargeMsgHdl ,
1295
+ current_file = LargeMsgFile ,
1296
+ current_file_offset = TotalSize })
1290
1297
end ,
1291
1298
% % Roll over to the next file.
1292
1299
NextFile = LargeMsgFile + 1 ,
@@ -1299,7 +1306,7 @@ write_large_message(MsgId, MsgBodyBin,
1299
1306
% % Delete messages from the cache that were written to disk.
1300
1307
true = ets :match_delete (CurFileCacheEts , {'_' , '_' , 0 }),
1301
1308
% % Process confirms (this won't flush; we already did) and continue.
1302
- State = internal_sync (State0 ),
1309
+ State = internal_sync (State1 ),
1303
1310
State # msstate { current_file_handle = NextHdl ,
1304
1311
current_file = NextFile ,
1305
1312
current_file_offset = 0 }.
0 commit comments