You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@bookkeeper.apache.org by "Sijie Guo (JIRA)" <ji...@apache.org> on 2012/05/31 17:25:23 UTC

[jira] [Comment Edited] (BOOKKEEPER-220) Managed Ledger proposal

    [ https://issues.apache.org/jira/browse/BOOKKEEPER-220?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13286645#comment-13286645 ] 

Sijie Guo edited comment on BOOKKEEPER-220 at 5/31/12 3:24 PM:
---------------------------------------------------------------

> ManagedLedgerImpl.addEntry is synchronized so there's should be no race condition there, but the problem was that the sync LedgerHandle.addEntry() doesn't return the entryId (like the asyncAddEntry does)

if one addEntry and one asyncAddEntry executed at the same time, what would happen?

thanks for reminding. seems that there is inconsistent between asyncAddEntry and addEntry. it should be a bug to fix.

> I think the race condition could be fixed by "syncronyzing" the ManagedLedgerFactoryImpl.open(), that way at most one instance will be created for the same ManagedLedger

yes. 'synchronized' is a quick fix. but I think putting a lot of initialize work in constructor is not so good.

could you consider putting the initialize work in a method like initailize().

so the open method could be as below:

{code}
    public ManagedLedger open(String name, ManagedLedgerConfig config) throws Exception {
        ManagedLedger ledger = ledgers.get(name);
        if (ledger != null) {
            log.info("Reusing opened ManagedLedger: {}", name);
            return ledger;
        } else {
            ledger = new ManagedLedgerImpl(this, bookKeeper, store, config, executor, name);
            ManagedLedger oldValue = ledgers.putIfAbsent(name, ledger);
            if (oldValue != null) {
                return oldValue;
            } else {
                // we get the change to initialize managedledger
                ledger.initialize();
                
                return ledger;
            }
        }   
    }
{code}



                
      was (Author: hustlmsp):
    > ManagedLedgerImpl.addEntry is synchronized so there's should be no race condition there, but the problem was that the sync LedgerHandle.addEntry() doesn't return the entryId (like the asyncAddEntry does)

if one addEntry and one asyncAddEntry executed at the same time, what would happen?

thanks for reminding. seems that there is inconsistent between asyncAddEntry and addEntry. it should be a bug to fix.

> I think the race condition could be fixed by "syncronyzing" the ManagedLedgerFactoryImpl.open(), that way at most one instance will be created for the same ManagedLedger

yes. 'synchronized' is a quick fix. but I think putting a lot of initialize work in constructor is not so good.

could you consider putting the initialize work in a method like initailize().

so the open method could be as below:

{code}
    public ManagedLedger open(String name, ManagedLedgerConfig config) throws Exception {
        ManagedLedger ledger = ledgers.get(name);
        if (ledger != null) {
            log.info("Reusing opened ManagedLedger: {}", name);
            return ledger;
        } else {
            ledger = new ManagedLedgerImpl(this, bookKeeper, store, config, executor, name);
            ManagedLedger oldValue = ledgers.putIfAbsent(name, ledger);
            if (oldValue != null) {
                // we get the change to initialize managedledger
                ledger.initialize();
                return oldValue;
            } else {
                return ledger;
            }
        }   
    }
{code}




                  
> Managed Ledger proposal
> -----------------------
>
>                 Key: BOOKKEEPER-220
>                 URL: https://issues.apache.org/jira/browse/BOOKKEEPER-220
>             Project: Bookkeeper
>          Issue Type: New Feature
>          Components: bookkeeper-client
>            Reporter: Matteo Merli
>            Assignee: Matteo Merli
>             Fix For: 4.2.0
>
>         Attachments: 0001-BOOKKEEPER-220-Managed-Ledger-proposal.patch
>
>
> The ManagedLedger design is based on our need to manage a set of ledgers, with a single writer (at any point in time) and a set on consumers that read entries from it. 
> The ManagedLedger also takes care of periodically closing ledgers to have a "reasonable" sized sets of ledgers that can individually deleted when no more needed.
> I've put on github the interface proposal (along with an early WIP implementation)
> http://github.com/merlimat/managed-ledger

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira