blerer commented on code in PR #2807:
URL: https://github.com/apache/cassandra/pull/2807#discussion_r1365216397


##########
src/java/org/apache/cassandra/schema/DistributedSchema.java:
##########
@@ -18,38 +18,261 @@
 
 package org.apache.cassandra.schema;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.UUID;
 
 import com.google.common.base.Preconditions;
 
+import org.apache.cassandra.db.Keyspace;
+import org.apache.cassandra.db.Mutation;
+import org.apache.cassandra.io.util.DataInputPlus;
+import org.apache.cassandra.io.util.DataOutputPlus;
+import org.apache.cassandra.tcm.Epoch;
+import org.apache.cassandra.tcm.MetadataValue;
+import org.apache.cassandra.tcm.serialization.MetadataSerializer;
+import org.apache.cassandra.tcm.serialization.Version;
+import org.apache.cassandra.utils.FBUtilities;
+
+import static org.apache.cassandra.db.TypeSizes.sizeof;
+
 /**
  * Immutable snapshot of the current schema along with its version.
  */
-public class DistributedSchema
+public class DistributedSchema implements MetadataValue<DistributedSchema>
 {
-    public static final DistributedSchema EMPTY = new 
DistributedSchema(Keyspaces.none(), SchemaConstants.emptyVersion);
+    public static final Serializer serializer = new Serializer();
+
+    /**
+     * A schema without any keyspace.
+     * @return a schema without any keyspace.
+     */
+    public static final DistributedSchema empty()
+    {
+        return new DistributedSchema(Keyspaces.none(), Epoch.EMPTY);
+    }
+
+    public static DistributedSchema first()
+    {
+        return new 
DistributedSchema(Keyspaces.of(DistributedMetadataLogKeyspace.metadata()), 
Epoch.FIRST);
+    }
 
     private final Keyspaces keyspaces;
+    private final Epoch epoch;
     private final UUID version;
+    private final Map<String, Keyspace> keyspaceInstances = new HashMap<>();
+
+    public DistributedSchema(Keyspaces keyspaces)
+    {
+        this(keyspaces, Epoch.EMPTY);
+    }
 
-    public DistributedSchema(Keyspaces keyspaces, UUID version)
+    public DistributedSchema(Keyspaces keyspaces, Epoch epoch)
     {
         Objects.requireNonNull(keyspaces);
-        Objects.requireNonNull(version);
         this.keyspaces = keyspaces;
-        this.version = version;
+        this.epoch = epoch;
+        this.version = new UUID(0, epoch.getEpoch());
         validate();
     }
 
+    @Override
+    public DistributedSchema withLastModified(Epoch epoch)
+    {
+        return new DistributedSchema(keyspaces, epoch);
+    }
+
+    @Override
+    public Epoch lastModified()
+    {
+        return epoch;
+    }
+
+    public Keyspace getKeyspace(String keyspace)
+    {
+        return keyspaceInstances.get(keyspace);
+    }
+
+    public KeyspaceMetadata getKeyspaceMetadata(String keyspace)
+    {
+        return keyspaces.get(keyspace).get();
+    }
+
+    public static DistributedSchema fromSystemTables(Keyspaces keyspaces)
+    {
+        if 
(!keyspaces.containsKeyspace(SchemaConstants.METADATA_KEYSPACE_NAME))
+            keyspaces = 
keyspaces.with(DistributedMetadataLogKeyspace.metadata());
+        return new DistributedSchema(keyspaces, Epoch.UPGRADE_GOSSIP);
+    }
+
+    public void initializeKeyspaceInstances(DistributedSchema prev)
+    {
+        initializeKeyspaceInstances(prev, true);
+    }
+
+    public void initializeKeyspaceInstances(DistributedSchema prev, boolean 
loadSSTables)

Review Comment:
   Yes, this part confused me too.



-- 
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]

Reply via email to