1 package org.apache.labs.bananadb.store.data;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import org.apache.labs.bananadb.store.lock.LockFactory;
22
23 import java.io.RandomAccessFile;
24 import java.io.IOException;
25 import java.io.File;
26
27
28
29
30
31 public class Metadata extends FileHandler<Metadata.Header, FileHandler.Posting> {
32
33 public Metadata(File directory, String access, LockFactory lockFactory) throws IOException {
34 super(directory, 0, "md", access, lockFactory);
35 }
36
37 public static final int HEADER_BYTE_SIZE = 1024;
38 public int getHeaderByteSize() {
39 return HEADER_BYTE_SIZE;
40 }
41
42 public static class Header extends FileHandler.Header {
43
44
45
46 private int fileFormatVersion;
47
48
49
50
51 private int currentHashtableId;
52
53
54 private int currentHashCodesPartition;
55
56
57 private int currentKeysPartition;
58
59
60 private int currentValuesPartition;
61
62
63
64
65 private long valuePostingsCount;
66
67
68
69
70 private long storeRevision;
71
72 public int getCurrentHashCodesPartition() {
73 return currentHashCodesPartition;
74 }
75
76 public void setCurrentHashCodesPartition(int currentHashCodesPartition) {
77 this.currentHashCodesPartition = currentHashCodesPartition;
78 }
79
80 public int getCurrentKeysPartition() {
81 return currentKeysPartition;
82 }
83
84 public void setCurrentKeysPartition(int currentKeysPartition) {
85 this.currentKeysPartition = currentKeysPartition;
86 }
87
88 public int getCurrentValuesPartition() {
89 return currentValuesPartition;
90 }
91
92 public void setCurrentValuesPartition(int currentValuesPartition) {
93 this.currentValuesPartition = currentValuesPartition;
94 }
95
96 public int getFileFormatVersion() {
97 return fileFormatVersion;
98 }
99
100 public void setFileFormatVersion(int fileFormatVersion) {
101 this.fileFormatVersion = fileFormatVersion;
102 }
103
104 public int getCurrentHashtableId() {
105 return currentHashtableId;
106 }
107
108 public void setCurrentHashtableId(int currentHashtableId) {
109 this.currentHashtableId = currentHashtableId;
110 }
111
112 public long getValuePostingsCount() {
113 return valuePostingsCount;
114 }
115
116 public void setValuePostingsCount(long valuePostingsCount) {
117 this.valuePostingsCount = valuePostingsCount;
118 }
119
120 public long getStoreRevision() {
121 return storeRevision;
122 }
123
124 public void setStoreRevision(long storeRevision) {
125 this.storeRevision = storeRevision;
126 }
127
128 public long increaseRevision(long value) {
129 return storeRevision += value;
130 }
131
132 public long increaseValuePostingsCount(long value) {
133 return valuePostingsCount += value;
134 }
135
136 public long decreaseValuePostingsCount(long value) {
137 return valuePostingsCount -= value;
138 }
139
140 }
141
142 public void readHeader(Header header, RandomAccessFile RAF) throws IOException {
143 header.fileFormatVersion = RAF.readInt();
144 header.storeRevision = RAF.readLong();
145 header.currentHashtableId = RAF.readInt();
146 header.currentHashCodesPartition = RAF.readInt();
147 header.currentKeysPartition = RAF.readInt();
148 header.currentValuesPartition = RAF.readInt();
149 header.valuePostingsCount = RAF.readLong();
150 System.currentTimeMillis();
151 }
152
153 public void writeHeader(Header header, RandomAccessFile RAF) throws IOException {
154 RAF.writeInt(header.fileFormatVersion);
155 RAF.writeLong(header.storeRevision);
156 RAF.writeInt(header.currentHashtableId);
157 RAF.writeInt(header.currentHashCodesPartition);
158 RAF.writeInt(header.currentKeysPartition);
159 RAF.writeInt(header.currentValuesPartition);
160 RAF.writeLong(header.valuePostingsCount);
161 }
162
163 public void writePosting(Posting posting, RandomAccessFile RAF) throws IOException {
164 throw new UnsupportedOperationException();
165 }
166
167 public void readPosting(Posting posting, RandomAccessFile RAF) throws IOException {
168 throw new UnsupportedOperationException();
169 }
170
171 public void markPostingAsDeleted(int startOffset, RandomAccessFile RAF, long revision) throws IOException {
172 throw new UnsupportedOperationException();
173 }
174 }