You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/05/14 01:48:40 UTC

[GitHub] [incubator-doris] morningman commented on a diff in pull request #9554: Add StoragePolicyResource for Remote Storage

morningman commented on code in PR #9554:
URL: https://github.com/apache/incubator-doris/pull/9554#discussion_r872911814


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/StoragePolicyResource.java:
##########
@@ -0,0 +1,128 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.catalog;
+
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.proc.BaseProcResult;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.gson.annotations.SerializedName;
+
+import java.util.Map;
+
+/**
+ * Policy resource for olap table
+ *
+ * Syntax:
+ * CREATE RESOURCE "storage_policy_name"
+ * PROPERTIES(
+ *      "type"="storage_policy",
+ *      "cooldown_datetime" = "2022-06-01", // time when data is transfter to medium
+ *      "cooldown_ttl" = "1h", // data is transfter to medium after 1 hour
+ *      "s3_resource" = "my_s3" // point to a s3 resource
+ * );
+ */
+public class StoragePolicyResource extends Resource {
+    // required
+    private static final String STORAGE_RESOURCE = "storage_resource";
+    // optional
+    private static final String COOLDOWN_DATETIME = "cooldown_datetime";
+    private static final String COOLDOWN_TTL = "cooldown_ttl";
+
+    private static final String DEFAULT_COOLDOWN_DATETIME = "9999-01-01 00:00:00";
+    private static final String DEFAULT_COOLDOWN_TTL = "1h";
+
+    @SerializedName(value = "properties")
+    private Map<String, String> properties;
+
+    public StoragePolicyResource(String name) {
+        this(name, Maps.newHashMap());
+    }
+
+    public StoragePolicyResource(String name, Map<String, String> properties) {
+        super(name, ResourceType.STORAGE_POLICY);
+        this.properties = properties;
+    }
+
+    public String getProperty(String propertyKey) {
+        return properties.get(propertyKey);
+    }
+
+    @Override
+    protected void setProperties(Map<String, String> properties) throws DdlException {
+        Preconditions.checkState(properties != null);
+        this.properties = properties;
+        // check properties
+        // required
+        checkRequiredProperty(STORAGE_RESOURCE);
+        // optional
+        checkOptionalProperty(COOLDOWN_DATETIME, DEFAULT_COOLDOWN_DATETIME);
+        checkOptionalProperty(COOLDOWN_TTL, DEFAULT_COOLDOWN_TTL);
+    }
+
+    private void checkRequiredProperty(String propertyKey) throws DdlException {
+        String value = properties.get(propertyKey);
+
+        if (Strings.isNullOrEmpty(value)) {
+            throw new DdlException("Missing [" + propertyKey + "] in properties.");
+        }
+    }
+
+    private void checkOptionalProperty(String propertyKey, String defaultValue) {
+        this.properties.putIfAbsent(propertyKey, defaultValue);
+    }
+
+    @Override
+    public void modifyProperties(Map<String, String> properties) throws DdlException {
+        // modify properties
+        replaceIfEffectiveValue(this.properties, STORAGE_RESOURCE, properties.get(STORAGE_RESOURCE));
+        replaceIfEffectiveValue(this.properties, COOLDOWN_DATETIME, properties.get(COOLDOWN_DATETIME));

Review Comment:
   We should check that only one of `COOLDOWN_DATETIME` and `COOLDOWN_TTL` can be specified



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/StoragePolicyResource.java:
##########
@@ -0,0 +1,128 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.catalog;
+
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.proc.BaseProcResult;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.gson.annotations.SerializedName;
+
+import java.util.Map;
+
+/**
+ * Policy resource for olap table
+ *
+ * Syntax:
+ * CREATE RESOURCE "storage_policy_name"
+ * PROPERTIES(
+ *      "type"="storage_policy",
+ *      "cooldown_datetime" = "2022-06-01", // time when data is transfter to medium
+ *      "cooldown_ttl" = "1h", // data is transfter to medium after 1 hour
+ *      "s3_resource" = "my_s3" // point to a s3 resource
+ * );
+ */
+public class StoragePolicyResource extends Resource {
+    // required
+    private static final String STORAGE_RESOURCE = "storage_resource";
+    // optional
+    private static final String COOLDOWN_DATETIME = "cooldown_datetime";
+    private static final String COOLDOWN_TTL = "cooldown_ttl";
+
+    private static final String DEFAULT_COOLDOWN_DATETIME = "9999-01-01 00:00:00";
+    private static final String DEFAULT_COOLDOWN_TTL = "1h";
+
+    @SerializedName(value = "properties")
+    private Map<String, String> properties;
+
+    public StoragePolicyResource(String name) {
+        this(name, Maps.newHashMap());
+    }
+
+    public StoragePolicyResource(String name, Map<String, String> properties) {
+        super(name, ResourceType.STORAGE_POLICY);
+        this.properties = properties;
+    }
+
+    public String getProperty(String propertyKey) {
+        return properties.get(propertyKey);
+    }
+
+    @Override
+    protected void setProperties(Map<String, String> properties) throws DdlException {
+        Preconditions.checkState(properties != null);
+        this.properties = properties;
+        // check properties
+        // required
+        checkRequiredProperty(STORAGE_RESOURCE);
+        // optional
+        checkOptionalProperty(COOLDOWN_DATETIME, DEFAULT_COOLDOWN_DATETIME);
+        checkOptionalProperty(COOLDOWN_TTL, DEFAULT_COOLDOWN_TTL);
+    }
+
+    private void checkRequiredProperty(String propertyKey) throws DdlException {
+        String value = properties.get(propertyKey);
+
+        if (Strings.isNullOrEmpty(value)) {
+            throw new DdlException("Missing [" + propertyKey + "] in properties.");
+        }
+    }
+
+    private void checkOptionalProperty(String propertyKey, String defaultValue) {
+        this.properties.putIfAbsent(propertyKey, defaultValue);
+    }
+
+    @Override
+    public void modifyProperties(Map<String, String> properties) throws DdlException {
+        // modify properties
+        replaceIfEffectiveValue(this.properties, STORAGE_RESOURCE, properties.get(STORAGE_RESOURCE));
+        replaceIfEffectiveValue(this.properties, COOLDOWN_DATETIME, properties.get(COOLDOWN_DATETIME));
+        replaceIfEffectiveValue(this.properties, COOLDOWN_TTL, properties.get(COOLDOWN_TTL));
+    }
+
+    @Override
+    public void checkProperties(Map<String, String> properties) throws AnalysisException {
+        // check properties
+        Map<String, String> copiedProperties = Maps.newHashMap(properties);
+        copiedProperties.remove(STORAGE_RESOURCE);
+        copiedProperties.remove(COOLDOWN_DATETIME);
+        copiedProperties.remove(COOLDOWN_TTL);
+
+        if (!copiedProperties.isEmpty()) {
+            throw new AnalysisException("Unknown S3 resource properties: " + copiedProperties);
+        }
+    }
+
+    @Override
+    public Map<String, String> getCopiedProperties() {
+        Map<String, String> copiedProperties = Maps.newHashMap(properties);
+        return copiedProperties;

Review Comment:
   ```suggestion
           return Maps.newHashMap(properties);
   ```



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org