Skip to content

Commit

Permalink
fix-alibaba#3550. write cache file and delete the old version cache f…
Browse files Browse the repository at this point in the history
…ile (alibaba#3551)
  • Loading branch information
horizonzy authored Aug 10, 2020
1 parent c45542c commit c9b64e0
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ private synchronized Datum readDatum(File file, String namespaceId) throws IOExc
}
}

private String cacheFileName(String namespaceId, Datum datum) {
private String cacheFileName(String namespaceId, String datumKey) {
String fileName;
if (StringUtils.isNotBlank(namespaceId)) {
fileName = CACHE_DIR + File.separator + namespaceId + File.separator + encodeDatumKey(datum.key);
fileName = CACHE_DIR + File.separator + namespaceId + File.separator + encodeDatumKey(datumKey);
} else {
fileName = CACHE_DIR + File.separator + encodeDatumKey(datum.key);
fileName = CACHE_DIR + File.separator + encodeDatumKey(datumKey);
}
return fileName;
}
Expand All @@ -259,7 +259,7 @@ public synchronized void write(final Datum datum) throws Exception {

String namespaceId = KeyBuilder.getNamespace(datum.key);

File cacheFile = cacheFile(cacheFileName(namespaceId, datum));
File cacheFile = cacheFile(cacheFileName(namespaceId, datum.key));

if (!cacheFile.exists() && !cacheFile.getParentFile().mkdirs() && !cacheFile.createNewFile()) {
MetricsMonitor.getDiskException().increment();
Expand Down Expand Up @@ -288,10 +288,10 @@ public synchronized void write(final Datum datum) throws Exception {
// remove old format file:
if (StringUtils.isNoneBlank(namespaceId)) {
if (datum.key.contains(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER)) {
String oldFormatKey = datum.key
String oldDatumKey = datum.key
.replace(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER, StringUtils.EMPTY);

cacheFile = cacheFile(cacheFileName(namespaceId, datum));
cacheFile = cacheFile(cacheFileName(namespaceId, oldDatumKey));
if (cacheFile.exists() && !cacheFile.delete()) {
Loggers.RAFT.error("[RAFT-DELETE] failed to delete old format datum: {}, value: {}", datum.key,
datum.value);
Expand Down Expand Up @@ -322,7 +322,7 @@ public void delete(Datum datum) {

if (StringUtils.isNotBlank(namespaceId)) {

File cacheFile = new File(cacheFileName(namespaceId, datum));
File cacheFile = new File(cacheFileName(namespaceId, datum.key));
if (cacheFile.exists() && !cacheFile.delete()) {
Loggers.RAFT.error("[RAFT-DELETE] failed to delete datum: {}, value: {}", datum.key, datum.value);
throw new IllegalStateException("failed to delete datum: " + datum.key);
Expand Down

0 comments on commit c9b64e0

Please sign in to comment.