elasticsearch/elasticsearch — pull request #7564 by dakrone (2014-09-03 13:36:05+00:00)
Title: Clean up translog interface

This has two major parts:

- Simplifying the translog interface

Get rid of readSource() entirely, it sucked, Operations should be able
to provide the source themselves.

No more TranslogStream headers, you are now required to pass an
StreamInput or StreamOutput for all operations, which means no extra
state is needed and no need to construct new versions when detecting the
version.

The interface now exists of 2 main methods, and one helper:

```java
// read
Translog.Operation read(StreamInput in)
// write
void write(StreamOutput out, Translog.Operation op)
// when reading a file, need to be able to read and consume the header
void seekPastHeader(StreamInput in)
```

-----

- Read and write translog op sizes in TranslogStreams

Previously we handled these integers outside of the translog stream
itself, which was very unclean because other code had to know about
reading the size, or about writing the correct header sometimes.

There is some additional code in LocalIndexShardGateway to handle the
legacy case for older translogs, because we need to read and discard the
size in order to maintain the compatibility for the streaming
operations (they did not read or write the size for 1.3.x and earlier).

Additionally, we need to handle a case where the header is truncated
when recovering from disk, so added code for that.

-----

I'm hoping this makes working with the translog easier and less error-prone. On top of this (in a separate PR) we can add the size-reading safety to prevent rare OOMEs on corrupted translogs.