@@ -148,9 +148,12 @@ private long getLastEntryInLedgerInternal(long ledgerId) throws IOException {
148148
149149 public void addLocation (long ledgerId , long entryId , long location ) throws IOException {
150150 Batch batch = locationsDb .newBatch ();
151- addLocation (batch , ledgerId , entryId , location );
152- batch .flush ();
153- batch .close ();
151+ try {
152+ addLocation (batch , ledgerId , entryId , location );
153+ batch .flush ();
154+ } finally {
155+ batch .close ();
156+ }
154157 }
155158
156159 public Batch newBatch () {
@@ -179,17 +182,19 @@ public void updateLocations(Iterable<EntryLocation> newLocations) throws IOExcep
179182 }
180183
181184 Batch batch = newBatch ();
182- // Update all the ledger index pages with the new locations
183- for (EntryLocation e : newLocations ) {
184- if (log .isDebugEnabled ()) {
185- log .debug ("Update location - ledger: {} -- entry: {}" , e .ledger , e .entry );
186- }
185+ try {
186+ // Update all the ledger index pages with the new locations
187+ for (EntryLocation e : newLocations ) {
188+ if (log .isDebugEnabled ()) {
189+ log .debug ("Update location - ledger: {} -- entry: {}" , e .ledger , e .entry );
190+ }
187191
188- addLocation (batch , e .ledger , e .entry , e .location );
192+ addLocation (batch , e .ledger , e .entry , e .location );
193+ }
194+ batch .flush ();
195+ } finally {
196+ batch .close ();
189197 }
190-
191- batch .flush ();
192- batch .close ();
193198 }
194199
195200 public void delete (long ledgerId ) throws IOException {
0 commit comments