You are viewing a plain text version of this content. The canonical link for it is here.
Posted to distributedlog-dev@bookkeeper.apache.org by khurrumnasimm <gi...@git.apache.org> on 2016/08/25 08:25:06 UTC

[GitHub] incubator-distributedlog pull request #15: DL-37: add an offset sequencer fo...

GitHub user khurrumnasimm opened a pull request:

    https://github.com/apache/incubator-distributedlog/pull/15

    DL-37: add an offset sequencer for generating transaction id

    add an offset sequencer for generating transaction id.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/khurrumnasimm/incubator-distributedlog offset_sequencer

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-distributedlog/pull/15.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #15
    
----
commit f63aab74cf08ba224019c7a860863225c018e463
Author: Khurrum Nasim <kh...@gmail.com>
Date:   2016-08-25T08:15:39Z

    add an offset sequencer for generating transaction id

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-distributedlog pull request #15: DL-37: add an offset sequencer fo...

Posted by leighst <gi...@git.apache.org>.
Github user leighst commented on a diff in the pull request:

    https://github.com/apache/incubator-distributedlog/pull/15#discussion_r76434565
  
    --- Diff: distributedlog-core/src/main/java/com/twitter/distributedlog/util/OffsetSequencer.java ---
    @@ -0,0 +1,51 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package com.twitter.distributedlog.util;
    +
    +import com.twitter.distributedlog.LogRecord;
    +
    +/**
    + * Offset based sequencer. It generated non-decreasing transaction id using offsets.
    + * It isn't thread-safe. The caller takes the responsibility on synchronization.
    + */
    +public class OffsetSequencer implements Sequencer {
    +
    +    private long lastOffset = -1L;
    +
    +    @Override
    +    public void setLastId(long lastId) {
    +        // NOTE: it is a bit tricky here. when a log stream is recovered, we can only get the last transaction id,
    +        //       but not the length of last record. so we don't know how many `bytes` to advance. so just to advance
    +        //       one here.
    +        this.lastOffset = lastId + 1;
    --- End diff --
    
    what if we make the offset here represent the next offset?
    ex. 
    [0 0] -> offset = 2
    [0 0] -> offset = 4


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-distributedlog issue #15: DL-37: add an offset sequencer for gener...

Posted by sijie <gi...@git.apache.org>.
Github user sijie commented on the issue:

    https://github.com/apache/incubator-distributedlog/pull/15
  
    I am not sure if we should support this. I had the same feeling with @leighst - I don't think we can find a reliable to use transaction id for offset.
    
    I am actually thinking in a different solution - we already have the length field for each entry appended to bookkeeper ledger. we probably can just expose this length field to the log segment metadata (like what we did for sequence id). so those length field can be used as the offset for batch of records (aka entries). does that meet your requirement, @khurrumnasimm ? /cc @leighst 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-distributedlog issue #15: DL-37: add an offset sequencer for gener...

Posted by khurrumnasimm <gi...@git.apache.org>.
Github user khurrumnasimm commented on the issue:

    https://github.com/apache/incubator-distributedlog/pull/15
  
    @sijie @leighst  thank you so much for your comments. I agreed with you after trying a while, it turns out is a bit hard to get an offset generator correctly on write proxy. I will fall back to use sequence id for my use case now. I will close the pull request and create a jira to expose offset.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-distributedlog pull request #15: DL-37: add an offset sequencer fo...

Posted by leighst <gi...@git.apache.org>.
Github user leighst commented on a diff in the pull request:

    https://github.com/apache/incubator-distributedlog/pull/15#discussion_r76433771
  
    --- Diff: distributedlog-service/src/main/java/com/twitter/distributedlog/service/stream/StreamImpl.java ---
    @@ -239,6 +231,12 @@ private DistributedLogManager openLog(String name) throws IOException {
         // Expensive initialization, only called once per stream.
         @Override
         public void initialize() throws IOException {
    +        try {
    +            sequencer = ReflectionUtils.newInstance(dynConf.getStreamSequencerClass());
    --- End diff --
    
    will you actually need this to be modified on the fly? 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-distributedlog pull request #15: DL-37: add an offset sequencer fo...

Posted by khurrumnasimm <gi...@git.apache.org>.
Github user khurrumnasimm closed the pull request at:

    https://github.com/apache/incubator-distributedlog/pull/15


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---