MCPcopy Create free account
hub / github.com/e2wugui/zeze / load

Method load

ZezeJava/ZezeJava/src/main/java/Zeze/Transaction/TableX.java:176–296  ·  view source on GitHub ↗
(@NotNull K key)

Source from the content-addressed store, hash-verified

174 }
175
176 @SuppressWarnings("unchecked")
177 private @NotNull AtomicTupleRecord<K, V> load(@NotNull K key) {
178 var tkey = new TableKey(getId(), key);
179 while (true) {
180 var r = cache.getOrAdd(key, () -> new Record1<>(this, key, null));
181 r.enterFairLock(); // 对同一个记录,不允许重入。
182 V strongRef = null;
183 try {
184 if (r.getState() == StateRemoved)
185 continue; // 正在被删除,重新 GetOrAdd 一次。以后 _lock_check_ 里面会再次检查这个状态。
186
187 if (r.getState() == StateShare
188 || r.getState() == StateModify) {
189 var beforeTimestamp = r.getTimestamp(); // read timestamp before read value。see Record1.Commit
190 strongRef = (V)r.getSoftValue();
191 if (strongRef == null && !r.getDirty()) {
192 var find = localRocksCacheTable.find(this, key);
193 if (find != null) {
194 strongRef = find;
195 strongRef.initRootInfo(r.createRootInfoIfNeed(tkey), null);
196 r.setSoftValue(strongRef);
197 }
198 }
199 return new AtomicTupleRecord<>(r, strongRef, beforeTimestamp);
200 }
201
202 var acquire = r.acquire(StateShare, false, false);
203 //noinspection DataFlowIssue
204 r.setState(acquire.resultState);
205 if (r.getState() == StateInvalid) {
206 var msg = "Acquire Failed (Redo): " + r;
207 var txn = Transaction.getCurrent();
208 if (txn == null || txn.isCompleted())
209 throw new GoBackZeze(msg);
210 txn.throwRedoAndReleaseLock(getId(), msg, null);
211 // never run here
212 }
213 try {
214 verifyGlobalRecordState(key, r.getState() == StateModify);
215
216 r.setTimestamp(Record.getNextTimestamp());
217 r.setFreshAcquire();
218 var beforeTimestamp = r.getTimestamp();
219
220 var storage = this.storage;
221 if (storage != null) {
222 if (ZezeCounter.instance != null)
223 ZezeCounter.instance.getOrAddTableInfo(getId()).storageGet().increment();
224 strongRef = storage.getDatabaseTable().find(this, key);
225 if (strongRef != null)
226 rocksCachePut(key, strongRef);
227 else
228 rocksCacheRemove(key);
229 r.setSoftValue(strongRef); // r.Value still maybe null
230 // 【注意】这个变量不管 OldTable 中是否存在的情况。
231// r.setExistInBackDatabase(strongRef != null);
232
233 // 当记录删除时需要同步删除 OldTable,否则下一次又会从 OldTable 中找到。

Callers 5

getMethod · 0.95
getOrAddMethod · 0.95
putMethod · 0.95
removeMethod · 0.95
selectCopyMethod · 0.95

Calls 15

getCurrentMethod · 0.95
getNextTimestampMethod · 0.95
rocksCachePutMethod · 0.95
rocksCacheRemoveMethod · 0.95
enterFairLockMethod · 0.80
getSoftValueMethod · 0.80
setSoftValueMethod · 0.80
setFreshAcquireMethod · 0.80
getDatabaseTableMethod · 0.80
getLocalRocksCacheDbMethod · 0.80

Tested by

no test coverage detected