mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 14:54:54 +07:00
[vfs] cleanup & refactoring
+ changed method names, added javadoc GitOrigin-RevId: 1277e85187b2fb8a6fdeccff8ed786806ba4d6db
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bd2766f742
commit
4c3b919103
@@ -1337,9 +1337,14 @@ public final class FSRecordsImpl implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
int storeUnlinkedContent(@NotNull ByteArraySequence content) {
|
||||
/**
|
||||
* Stores content and return contentRecordId, by which content could be later retrieved.
|
||||
* If the same content (bytes) was already stored -- method could return id of already existing record, without allocating
|
||||
* & storing new record.
|
||||
*/
|
||||
int writeContentRecord(@NotNull ByteArraySequence content) {
|
||||
try {
|
||||
return contentAccessor.allocateContentRecordAndStore(content);
|
||||
return contentAccessor.writeContentRecord(content);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw handleError(e);
|
||||
|
||||
@@ -43,13 +43,18 @@ public final class PersistentFSContentAccessor {
|
||||
PersistentFSConnection.ensureIdIsValid(fileId);
|
||||
PersistentFSRecordsStorage records = connection.getRecords();
|
||||
|
||||
int contentRecordId = allocateContentRecordAndStore(content);
|
||||
int contentRecordId = writeContentRecord(content);
|
||||
|
||||
records.setContentRecordId(fileId, contentRecordId);
|
||||
}
|
||||
|
||||
|
||||
int allocateContentRecordAndStore(@NotNull ByteArraySequence content) throws IOException {
|
||||
/**
|
||||
* Stores content and return contentRecordId, by which content could be later retrieved.
|
||||
* If the same content (bytes) was already stored -- method could return id of already existing record, without allocating
|
||||
* & storing new record.
|
||||
*/
|
||||
int writeContentRecord(@NotNull ByteArraySequence content) throws IOException {
|
||||
return connection.getContents().storeRecord(content);
|
||||
}
|
||||
|
||||
|
||||
@@ -488,7 +488,7 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable {
|
||||
|
||||
@Override
|
||||
public int storeUnlinkedContent(byte @NotNull [] bytes) {
|
||||
return vfsPeer.storeUnlinkedContent(new ByteArraySequence(bytes));
|
||||
return vfsPeer.writeContentRecord(new ByteArraySequence(bytes));
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
@@ -828,15 +828,7 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable {
|
||||
byte[] content = fs.contentsToByteArray(file);
|
||||
|
||||
if (mayCacheContent && shouldCache(content.length)) {
|
||||
//VFS content storage is append-only, hence storing could be done outside the lock:
|
||||
int newContentRecordId = vfsPeer.storeUnlinkedContent(new ByteArraySequence(content));
|
||||
myInputLock.writeLock().lock();
|
||||
try {
|
||||
updateContentId(fileId, newContentRecordId, content.length);
|
||||
}
|
||||
finally {
|
||||
myInputLock.writeLock().unlock();
|
||||
}
|
||||
updateContentForFile(fileId, new ByteArraySequence(content));
|
||||
}
|
||||
else {
|
||||
myInputLock.writeLock().lock();
|
||||
@@ -992,25 +984,26 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable {
|
||||
|
||||
if (byteLength == fileLength) {
|
||||
ByteArraySequence newContent = new ByteArraySequence(bytes, 0, byteLength);
|
||||
int newContentId = vfsPeer.storeUnlinkedContent(newContent);
|
||||
myInputLock.writeLock().lock();
|
||||
try {
|
||||
updateContentId(fileId, newContentId, byteLength);
|
||||
}
|
||||
finally {
|
||||
myInputLock.writeLock().unlock();
|
||||
}
|
||||
updateContentForFile(fileId, newContent);
|
||||
}
|
||||
else {
|
||||
doCleanPersistedContent(fileId);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateContentForFile(int fileId,
|
||||
@NotNull ByteArraySequence newContent) throws IOException {
|
||||
//VFS content storage is append-only, hence storing could be done outside the lock:
|
||||
int newContentId = vfsPeer.writeContentRecord(newContent);
|
||||
|
||||
myInputLock.writeLock().lock();
|
||||
try {
|
||||
doCleanPersistedContent(fileId);
|
||||
updateContentId(fileId, newContentId, newContent.length());
|
||||
}
|
||||
finally {
|
||||
myInputLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Method is obsolete, migrate to {@link #contentHashIfStored(VirtualFile)} instance method */
|
||||
@TestOnly
|
||||
@@ -2386,9 +2379,11 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable {
|
||||
|
||||
private void setFlag(int id, @Attributes int mask, boolean value) {
|
||||
int oldFlags = vfsPeer.getFlags(id);
|
||||
int flags = value ? oldFlags | mask : oldFlags & ~mask;
|
||||
int flags = value ? oldFlags | mask
|
||||
: oldFlags & ~mask;
|
||||
|
||||
if (oldFlags != flags) {
|
||||
//noinspection MagicConstant
|
||||
vfsPeer.setFlags(id, flags);
|
||||
}
|
||||
}
|
||||
@@ -2458,9 +2453,13 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable {
|
||||
}
|
||||
|
||||
private void doCleanPersistedContent(int id) {
|
||||
//TODO set in single call: setFlag(id, MUST_RELOAD_CONTENT | MUST_RELOAD_LENGTH, true);
|
||||
setFlag(id, Flags.MUST_RELOAD_CONTENT, true);
|
||||
setFlag(id, Flags.MUST_RELOAD_LENGTH, true);
|
||||
myInputLock.writeLock().lock();
|
||||
try {
|
||||
setFlag(id, Flags.MUST_RELOAD_CONTENT | Flags.MUST_RELOAD_LENGTH, true);
|
||||
}
|
||||
finally {
|
||||
myInputLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -393,7 +393,7 @@ object VfsRecoveryUtils {
|
||||
when (val nextContent = snapshot.getContent(lastRecoveredContentId + 1)) {
|
||||
is NotAvailable -> break
|
||||
is Ready -> {
|
||||
val result = newFsRecords.contentAccessor().allocateContentRecordAndStore(ByteArraySequence(nextContent.value))
|
||||
val result = newFsRecords.contentAccessor().writeContentRecord(ByteArraySequence(nextContent.value))
|
||||
check(result == lastRecoveredContentId + 1) { "assumption failed: got $result, expected ${lastRecoveredContentId + 1}" }
|
||||
lastRecoveredContentId++
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.util.io.storage;
|
||||
|
||||
import com.intellij.openapi.Forceable;
|
||||
@@ -25,7 +25,7 @@ public interface VFSContentStorage extends CleanableStorage, Closeable, Forceabl
|
||||
|
||||
/**
|
||||
* Stores bytes and return contentRecordId, by which content could be later retrieved.
|
||||
* If the same bytes was already stored -- method could return id of already existing record, without allocating
|
||||
* If the same content (bytes) was already stored -- method could return id of already existing record, without allocating
|
||||
* & storing new record.
|
||||
*/
|
||||
int storeRecord(@NotNull ByteArraySequence bytes) throws IOException;
|
||||
|
||||
Reference in New Issue
Block a user