Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page is meant as a template for writing a DP (DistributedLog Proposal). To create a DP choose DP-Template on creating a page and modify with your content and replace the heading with the next DP number and a description of your issue. Replace anything in italics with your own description.

Table of Contents

Status

Current state: [One of  "Under Discussion", "Accepted", "Rejected"]

Discussion thread: [link]

JIRA: [link]

Released: <DL version>0.5.0

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

Describe the problems you are trying to solve.

Public Interfaces

Briefly list any new interfaces that will be introduced as part of this proposal or any existing interfaces that will be removed or changed. The purpose of this section is to concisely call out the public contract that will come along with this feature.

A public interface is any change to the following:

  • Data format, Metadata format

  • The wire protocol and api behavior

  • Any class in the public packages

  • Monitoring

  • Command line tools and arguments

  • Anything else that will likely break existing users in some way when they upgrade

Proposed Changes

When using the distributedlog-client module writing data through distributedlog-service, the resulting state of the log stream is hard to predict. It is possible for a distributedlog client to end up writing duplicated records to a log stream, or having unexpected arriving order on records and create an inconsistent state.

This proposal here proposes adding a simple write primitive to the thin distributedlog client. The write primitive is a CAS (check-and-set) style operation. The client will attempt to write a record with a provided SN (sequence number) - if the provided SN does not match the SN of last written record, distributedlog-service should refuse serving the write request. The CAS style write lets the client confirm the current state of a log stream before going ahead with the write. The SN can be the system generated DLSN, the monotonically increasing Sequence ID or the user provided transaction id.

The CAS style write is useful in following use cases:

  • It will be very useful for bootstrapping a state machine – for example, when a state machine is restarted, it has to bootstrap from last snapshot and after the state machine is caught up with the latest commit, it completes bootstrap and writes new commits to the same log stream. The CAS style write can guarantee that the state machine will consume all the records at the moment it does the first successful write.
  • It will be useful for 'read-transform-write' tasks – for example, when a task is reading data from a HDFS file and loading the data into a log stream, the CAS style write can CAS on SN to guarantee the data will be copied just once.
  • It will be very useful for avoiding two concurrent writes to a log stream at the same time. As it would guarantee at least one of them will fail.

Comparing this with providing transactional support, it is much light weight.

Public Interfaces

The proposal requires a few additions to the protocol and the public interface.

The protocol changes are listed as below:

  • Add a new Struct 'SN'

    Code Block
    struct SN {
    	1: optional DLSN dlsn;
    	2: optional long transactionId;
    	3: optional long sequenceId;
    }
  • Add an optional field 'casSN' to WriteContext

    Code Block
    struct WriteContext {
    	...
    	4: optional SN casSN;
    }
  • Add a new status code

    Code Block
    CAS_WRITE_EXCEPTION = 525

The public API change will be:

Core Library Change:

  • Future<DLSN> write(LogRecord record, DLSN expectedDLSN);
  • Future<DLSN> write(LogRecord record, long expectedTransactionID);

Thin Client Change:

  • Future<DLSN> write(String stream, ByteBuffer data, DLSN expectedDLSN);
  • Future<DLSN> write(String stream, ByteBuffer data, long expectedTransactionID);

Proposed Changes

Currently the writer already have tracked the last transaction id and known of the entry id when writing records to a log segment. We can easily compare the provided 'expectedDLSN' and 'expectedTransactionID' when writing the records. It is a trivial Describe the new thing you want to do in appropriate detail. This may be fairly extensive and have large subsections of its own. Or it may be a few sentences. Use judgement based on the scope of the change.

Compatibility, Deprecation, and Migration Plan

  • What impact (if any) will there be on existing users? 
  • If we are changing behavior how will we phase out the older behavior? 
  • If we need special migration tools, describe them here.
  • When will we remove the existing behavior?

Test Plan

Describe in few sentences how the DP will be tested. We are mostly interested in system tests (since unit-tests are specific to implementation details). How will we know that the implementation works as expected? How will we know nothing broke?

Rejected Alternatives

  • This change only adds new API to the client. So the new server and the old client are backward compatible. It doesn't require special instructions for upgrading servers.

Rejected Alternatives

The other two DPs: DP-2 - Epoch Write Support and DP-1 - DistributedLog Transaction Support have quite a lot of overlaps with the use cases here. For example, a full fledged transaction would be able to support these use cases. However, this proposal here has provided a much trivial/lightweight extension to existing API and it imposes little to no runtime cost in memory or timeIf there are alternative ways of accomplishing the same thing, what were they? The purpose of this section is to motivate why the design is the way it is and not some other way.