8000 Issue #2381 was fixed. · githubcs/orientdb@917748e · GitHub
[go: up one dir, main page]

Skip to content

Commit 917748e

Browse files
Issue orientechnologies#2381 was fixed.
1 parent ee4fa2c commit 917748e

File tree

6 files changed

+72
-30
lines changed

6 files changed

+72
-30
lines changed

core/src/main/java/com/orientechnologies/orient/core/index/hashindex/local/cache/OWOWCache.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,11 +726,11 @@ public void renameFile(long fileId, String oldFileName, String newFileName) thro
726726
}
727727
}
728728

729-
writeNameIdEntry(new NameFileIdEntry(oldFileName, -1), false);
730-
writeNameIdEntry(new NameFileIdEntry(newFileName, fileId), true);
731-
732729
nameIdMap.remove(oldFileName);
733730
nameIdMap.put(newFileName, fileId);
731+
732+
writeNameIdEntry(new NameFileIdEntry(oldFileName, -1), false);
733+
writeNameIdEntry(new NameFileIdEntry(newFileName, fileId), true);
734734
}
735735
}
736736

core/src/main/java/com/orientechnologies/orient/core/storage/fs/OAbstractFile.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,11 @@ public String getAbsolutePath() {
819819
public boolean renameTo(final File newFile) {
820820
acquireWriteLock();
821821
try {
822-
return osFile.renameTo(newFile);
822+
final boolean renamed = osFile.renameTo(newFile);
823+
if (renamed)
824+
osFile = newFile;
825+
826+
return renamed;
823827
} finally {
824828
releaseWriteLock();
825829
}

core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/OClusterPositionMap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void delete() throws IOException {
123123
public void rename(String newName) throws IOException {
124124
acquireExclusiveLock();
125125
try {
126-
diskCache.renameFile(fileId, this.name, newName);
126+
diskCache.renameFile(fileId, this.name + DEF_EXTENSION, newName + DEF_EXTENSION);
127127
name = newName;
128128
} finally {
129129
releaseExclusiveLock();
@@ -191,8 +191,8 @@ public OClusterPositionMapBucket.PositionEntry get(OClusterPosition clusterPosit
191191
long pageIndex = position / OClusterPositionMapBucket.MAX_ENTRIES;
192192
int index = (int) (position % OClusterPositionMapBucket.MAX_ENTRIES);
193193

194-
if(pageIndex >= diskCache.getFilledUpTo(fileId))
195-
return null;
194+
if (pageIndex >= diskCache.getFilledUpTo(fileId))
195+
return null;
196196

197197
final OCacheEntry cacheEntry = diskCache.load(fileId, pageIndex, false);
198198
final OCachePointer cachePointer = cacheEntry.getCachePointer();

core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/OLocalPaginatedStorage.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public void open(final String iUserName, final String iUserPassword, final Map<S
211211
"Error on loading cluster '" + clusters.get(i).getName() + "' (" + i
212212
+ "): file not found. It will be excluded from current database '" + getName() + "'.");
213213

214-
clusterMap.remove(clusters.get(i).getName());
214+
clusterMap.remove(clusters.get(i).getName().toLowerCase());
215215

216216
setCluster(i, null);
217217
}
@@ -537,7 +537,7 @@ public boolean dropCluster(final int iClusterId, final boolean iTruncate) {
537537
cluster.delete();
538538

539539
dirtyFlag.makeDirty();
540-
clusterMap.remove(cluster.getName());
540+
clusterMap.remove(cluster.getName().toLowerCase());
541541
clusters.set(iClusterId, null);
542542

543543
// UPDATE CONFIGURATION
@@ -995,35 +995,35 @@ public Set<String> getClusterNames() {
995995
return new HashSet<String>(clusterMap.keySet());
996996
}
997997

998-
public int getClusterIdByName(final String iClusterName) {
998+
public int getClusterIdByName(final String сlusterName) {
999999
checkOpeness();
10001000

1001-
if (iClusterName == null)
1001+
if (сlusterName == null)
10021002
throw new IllegalArgumentException("Cluster name is null");
10031003

1004-
if (iClusterName.length() == 0)
1004+
if (сlusterName.length() == 0)
10051005
throw new IllegalArgumentException("Cluster name is empty");
10061006

1007-
if (Character.isDigit(iClusterName.charAt(0)))
1008-
return Integer.parseInt(iClusterName);
1007+
if (Character.isDigit(сlusterName.charAt(0)))
1008+
return Integer.parseInt(сlusterName);
10091009

10101010
// SEARCH IT BETWEEN PHYSICAL CLUSTERS
10111011

1012-
final OCluster segment = clusterMap.get(iClusterName.toLowerCase());
1012+
final OCluster segment = clusterMap.get(сlusterName.toLowerCase());
10131013
if (segment != null)
10141014
return segment.getId();
10151015

10161016
return -1;
10171017
}
10181018

1019-
public String getClusterTypeByName(final String iClusterName) {
1019+
public String getClusterTypeByName(final String сlusterName) {
10201020
checkOpeness();
10211021

1022-
if (iClusterName == null)
1022+
if (сlusterName == null)
10231023
throw new IllegalArgumentException("Cluster name is null");
10241024

10251025
// SEARCH IT BETWEEN PHYSICAL CLUSTERS
1026-
final OCluster segment = clusterMap.get(iClusterName.toLowerCase());
1026+
final OCluster segment = clusterMap.get(сlusterName.toLowerCase());
10271027
if (segment != null)
10281028
return segment.getType();
10291029

@@ -1185,11 +1185,11 @@ public OCluster getClusterById(int iClusterId) {
11851185
}
11861186

11871187
@Override
1188-
public OCluster getClusterByName(final String iClusterName) {
1189-
final OCluster cluster = clusterMap.get(iClusterName.toLowerCase());
1188+
public OCluster getClusterByName(final String сlusterName) {
1189+
final OCluster cluster = clusterMap.get(сlusterName.toLowerCase());
11901190

11911191
if (cluster == null)
1192-
throw new IllegalArgumentException("Cluster " + iClusterName + " does not exist in database '" + name + "'");
1192+
throw new IllegalArgumentException("Cluster " + сlusterName + " does not exist in database '" + name + "'");
11931193
return cluster;
11941194
}
11951195

@@ -1245,8 +1245,8 @@ public Set<OCluster> getClusterInstances() {
12451245
* Method that completes the cluster rename operation. <strong>IT WILL NOT RENAME A CLUSTER, IT JUST CHANGES THE NAME IN THE
12461246
* INTERNAL MAPPING</strong>
12471247
*/
1248-
public void renameCluster(final String iOldName, final String iNewName) {
1249-
clusterMap.put(iNewName.toLowerCase(), clusterMap.remove(iOldName.toLowerCase()));
1248+
public void renameCluster(final String oldName, final String newName) {
1249+
clusterMap.put(newName.toLowerCase(), clusterMap.remove(oldName.toLowerCase()));
12501250
}
12511251

12521252
@Override
@@ -2074,16 +2074,16 @@ private void checkClusterSegmentIndexRange(final int iClusterId) {
20742074
throw new IllegalArgumentException("Cluster segment #" + iClusterId + " does not exist in database '" + name + "'");
20752075
}
20762076

2077-
private int createClusterFromConfig(final OStorageClusterConfiguration iConfig) throws IOException {
2078-
OCluster cluster = clusterMap.get(iConfig.getName().toLowerCase());
2077+
private int createClusterFromConfig(final OStorageClusterConfiguration сonfig) throws IOException {
2078+
OCluster cluster = clusterMap.get(сonfig.getName().toLowerCase());
20792079

20802080
if (cluster != null) {
2081-
cluster.configure(this, iConfig);
2081+
cluster.configure(this, сonfig);
20822082
return -1;
20832083
}
20842084

20852085
cluster = OPaginatedClusterFactory.INSTANCE.createCluster(configuration.version);
2086-
cluster.configure(this, iConfig);
2086+
cluster.configure(this, сonfig);
20872087

20882088
return registerCluster(cluster);
20892089
}
@@ -2101,11 +2101,11 @@ private int registerCluster(final OCluster cluster) throws IOException {
21012101

21022102
if (cluster != null) {
21032103
// CHECK FOR DUPLICATION OF NAMES
2104-
if (clusterMap.containsKey(cluster.getName()))
2104+
if (clusterMap.containsKey(cluster.getName().toLowerCase()))
21052105
throw new OConfigurationException("Cannot add segment '" + cluster.getName()
21062106
+ "' because it is already registered in database '" + name + "'");
21072107
// CREATE AND ADD THE NEW REF SEGMENT
2108-
clusterMap.put(cluster.getName(), cluster);
2108+
clusterMap.put(cluster.getName().toLowerCase(), cluster);
21092109
id = cluster.getId();
21102110
} else {
21112111
id = clusters.size();

core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/paginated/OPaginatedCluster.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ private void setUseWalInternal(String stringValue) {
334334
}
335335

336336
private void setNameInternal(String newName) throws IOException {
337-
diskCache.renameFile(fileId, this.name, newName);
337+
diskCache.renameFile(fileId, this.name + DEF_EXTENSION, newName + DEF_EXTENSION);
338338
clusterPositionMap.rename(newName);
339339

340340
config.name = newName;

tests/src/test/java/com/orientechnologies/orient/test/database/auto/SchemaTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,4 +491,42 @@ public void testMinimumClustersAndClusterSelection() {
491491
}
492492
}
493493

494+
public void testExchangeCluster() {
495+
if (url.startsWith("memory:"))
496+
return;
497+
498+
ODatabaseDocumentTx databaseDocumentTx = new ODatabaseDocumentTx(url);
499+
databaseDocumentTx.open("admin", "admin");
500+
501+
try {
502+
databaseDocumentTx.command(new OCommandSQL("CREATE CLASS TestRenameClusterOriginal")).execute();
503+
504+
swapClusters(databaseDocumentTx, 1);
505+
swapClusters(databaseDocumentTx, 2);
506+
swapClusters(databaseDocumentTx, 3);
507+
} finally {
508+
databaseDocumentTx.close();
509+
}
510+
}
511+
512+
private void swapClusters(ODatabaseDocumentTx databaseDocumentTx, int i) {
513+
databaseDocumentTx.command(new OCommandSQL("CREATE CLASS TestRenameClusterNew extends TestRenameClusterOriginal")).execute();
514+
515+
databaseDocumentTx.command(new OCommandSQL("INSERT INTO TestRenameClusterNew (iteration) VALUES(" + i + ")")).execute();
516+
517+
databaseDocumentTx.command(new OCommandSQL("ALTER CLASS TestRenameClusterOriginal removecluster TestRenameClusterOriginal"))
518+
.execute();
519+
databaseDocumentTx.command(new OCommandSQL("ALTER CLASS TestRenameClusterNew removecluster TestRenameClusterNew")).execute();
520+
databaseDocumentTx.command(new OCommandSQL("DROP CLASS TestRenameClusterNew")).execute();
521+
databaseDocumentTx.command(new OCommandSQL("ALTER CLASS TestRenameClusterOriginal addcluster TestRenameClusterNew")).execute();
522+
databaseDocumentTx.command(new OCommandSQL("DROP CLUSTER TestRenameClusterOriginal")).execute();
523+
databaseDocumentTx.command(new OCommandSQL("ALTER CLUSTER TestRenameClusterNew name TestRenameClusterOriginal")).execute();
524+
525+
List<ODocument> result = databaseDocumentTx.query(new OSQLSynchQuery<ODocument>("select * from TestRenameClusterOriginal"));
526+
Assert.assertEquals(result.size(), 1);
527+
528+
ODocument document = result.get(0);
529+
Assert.assertEquals(document.field("iteration"), i);
530+
}
531+
494532
}

0 commit comments

Comments
 (0)
0