Improve segmented journal actor metrics
[controller.git] / atomix-storage / src / main / java / io / atomix / storage / journal / JournalWriter.java
1 /*
2  * Copyright 2017-2022 Open Networking Foundation and others.  All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package io.atomix.storage.journal;
17
18 import org.eclipse.jdt.annotation.NonNull;
19
20 /**
21  * Log writer.
22  *
23  * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
24  */
25 public interface JournalWriter<E> {
26     /**
27      * Returns the last written index.
28      *
29      * @return The last written index.
30      */
31     long getLastIndex();
32
33     /**
34      * Returns the last entry written.
35      *
36      * @return The last entry written.
37      */
38     Indexed<E> getLastEntry();
39
40     /**
41      * Returns the next index to be written.
42      *
43      * @return The next index to be written.
44      */
45     long getNextIndex();
46
47     /**
48      * Appends an entry to the journal.
49      *
50      * @param entry The entry to append.
51      * @return The appended indexed entry.
52      */
53     <T extends E> @NonNull Indexed<T> append(T entry);
54
55     /**
56      * Commits entries up to the given index.
57      *
58      * @param index The index up to which to commit entries.
59      */
60     void commit(long index);
61
62     /**
63      * Resets the head of the journal to the given index.
64      *
65      * @param index the index to which to reset the head of the journal
66      */
67     void reset(long index);
68
69     /**
70      * Truncates the log to the given index.
71      *
72      * @param index The index to which to truncate the log.
73      */
74     void truncate(long index);
75
76     /**
77      * Flushes written entries to disk.
78      */
79     void flush();
80 }