netudima commented on code in PR #4278:
URL: https://github.com/apache/cassandra/pull/4278#discussion_r2254606909
##########
src/java/org/apache/cassandra/io/sstable/format/TOCComponent.java:
##########
@@ -78,20 +80,36 @@ public static Set<Component> loadTOC(Descriptor descriptor,
boolean skipMissing)
}
/**
- * Appends new component names to the TOC component.
+ * Updates the TOC file by reading existing component entries, merging
them with the given components,
+ * sorting the combined list in lexicographic order for deterministic
output.
+ *
+ * @param descriptor the SSTable descriptor for which to update the TOC
+ * @param components new components to merge into the TOC (existing TOC
entries are preserved)
+ * @throws FSWriteError if an I/O error occurs when creating or
overwriting the TOC file
*/
- public static void appendTOC(Descriptor descriptor, Collection<Component>
components)
+ public static void updateTOC(Descriptor descriptor, Collection<Component>
components)
{
+ if (components.isEmpty())
+ return;
+
File tocFile = descriptor.fileFor(Components.TOC);
- try (FileOutputStreamPlus out = tocFile.newOutputStream(APPEND);
- PrintWriter w = new PrintWriter(out))
+
+ Set<String> componentNames = new
TreeSet<>(Collections2.transform(components, Component::name));
+
+ if (tocFile.exists())
{
- for (Component component : components)
- w.println(component.name);
- w.flush();
- out.sync();
+ List<String> lines = FileUtils.readLines(tocFile);
+ if (lines.isEmpty())
Review Comment:
we may open the file and start to write into it and at this moment Cassandra
process crashed (or host/VM is crashed), so in this case I think an operator
cannot do something meaningful manually - he/she will just remove the file or
add the lines by hand, so I think there is no need to introduce a burden for
manual interventions here, it will not help to detect and fix some data
inconsistency (compared to corrupted sstable data or commit log files) ...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]