Jia
I think we must do this before releasing 4.6

Enrico

Il ven 3 nov 2017, 06:48 Enrico Olivelli <eolive...@gmail.com> ha scritto:

>
>
> Il ven 3 nov 2017, 02:39 Sijie Guo <guosi...@gmail.com> ha scritto:
>
>> Hi Enrico,
>>
>> In the new ledger api, we return Iterable<LedgerEntry> instead of
>> Iterator<LedgerEntry>. In general, it is good to return Iterable, however
>> it seems to be problematic in following use case:
>>
>> Iterable<LedgerEntry> entries = rh.read(...);
>>
>> Iterator<LedgerEntry> iter1 = entries.iterator();
>> while (iter1.hasNext()) {
>>
>> LedgerEntry le = iter1.next;
>> le.getEntryBuffer().release();
>>
>> }
>>
>> Iterator<LedgerEntry> iter2 = entries.iterator();
>> while (iter2.hasNext()) {
>>
>> LedgerEntry le = iter2.next();
>> le.getEntryBuffer().release();
>>
>> }
>>
>> Using Iterable opens up the chance that people will create multiple
>> iterators and use them concurrently. I think we should not use
>> Iterable<LedgerEntry>, which it might actually cause problems.
>>
>> I am thinking if we can create an interface LedgerEntries to extend
>> Iterable<LedgerEntry>. so:
>>
>> - the implementation can create increase right buffer reference when
>> creating an iterator
>> - we can make LedgerEntries a recycleable object, and it is returned to
>> the tool when people called #close()
>> - on #close(), it releases all the references to release resources
>>
>> interface LedgerEntries extends Iterable<LedgerEntry>, AutoCloseable {
>>
>>        long getEntry(long entryId);
>>
>>        Iterator<LedgerEntry> iterator();
>>
>>
>> }
>>
>
>
> I think this is a great idea. I remember we already talked about something
> similar when we discovered the need to release buffers for v2 protocol but
> it was not possible for 4.5.
>
> Enrico
>
>> --
>
>
> -- Enrico Olivelli
>
-- 


-- Enrico Olivelli

Reply via email to