jack-moseley commented on a change in pull request #3414:
URL: https://github.com/apache/gobblin/pull/3414#discussion_r732295840



##########
File path: 
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/spec_store/MysqlNonFlowSpecStore.java
##########
@@ -0,0 +1,318 @@
+/*
+ * 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.gobblin.runtime.spec_store;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import com.google.common.io.ByteStreams;
+import com.typesafe.config.Config;
+
+import javax.sql.DataSource;
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.broker.SharedResourcesBrokerFactory;
+import org.apache.gobblin.configuration.ConfigurationKeys;
+import org.apache.gobblin.metastore.MysqlDataSourceFactory;
+import org.apache.gobblin.runtime.api.FlowSpec;
+import org.apache.gobblin.runtime.api.InstrumentedSpecStore;
+import org.apache.gobblin.runtime.api.Spec;
+import org.apache.gobblin.runtime.api.SpecNotFoundException;
+import org.apache.gobblin.runtime.api.SpecSerDe;
+import org.apache.gobblin.runtime.api.SpecSerDeException;
+import org.apache.gobblin.runtime.api.SpecStore;
+
+
+/**
+ * Implementation of {@link SpecStore} that stores specs (other than {@link 
FlowSpec}) in MySQL as a serialized BLOB, per the provided
+ * {@link SpecSerDe}.
+ * Note: versions are unsupported, so the version parameter is ignored in 
methods that have it.
+ *
+ * A tag column is added into implementation to serve certain filtering 
purposes in MySQL-based SpecStore.
+ * For example, in DR mode of GaaS, we would only want certain {@link Spec}s 
to be eligible for orchestrated
+ * by alternative GaaS instances. Another example is 
allow-listing/deny-listing {@link Spec}s temporarily
+ * but not removing it from {@link SpecStore}.
+ *
+ * The {@link MysqlSpecStore} is a specialization enhanced for {@link 
FlowSpec} search and retrieval.
+ */
+@Slf4j
+public class MysqlNonFlowSpecStore extends InstrumentedSpecStore {
+
+  /** `j.u.Function` variant for an operation that may @throw IOException or 
SQLException: preserves method signature checked exceptions */
+  @FunctionalInterface
+  protected interface CheckedFunction<T, R> {
+    R apply(T t) throws IOException, SQLException;
+  }
+
+  public static final String CONFIG_PREFIX = "mysqlNonFlowSpecStore";
+  public static final String DEFAULT_TAG_VALUE = "";
+
+  private static final String EXISTS_STATEMENT = "SELECT EXISTS(SELECT * FROM 
%s WHERE spec_uri = ?)";
+  protected static final String INSERT_STATEMENT = "INSERT INTO %s (spec_uri, 
tag, spec) "
+      + "VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE spec = VALUES(spec)";
+  private static final String DELETE_STATEMENT = "DELETE FROM %s WHERE 
spec_uri = ?";
+  private static final String GET_STATEMENT_BASE = "SELECT spec_uri, spec FROM 
%s WHERE ";
+  private static final String GET_ALL_STATEMENT = "SELECT spec_uri, spec FROM 
%s";
+  private static final String GET_ALL_URIS_STATEMENT = "SELECT spec_uri FROM 
%s";
+  private static final String GET_ALL_URIS_WITH_TAG_STATEMENT = "SELECT 
spec_uri FROM %s WHERE tag = ?";
+  private static final String GET_SIZE_STATEMENT = "SELECT COUNT(*) FROM %s ";
+  private static final String CREATE_TABLE_STATEMENT = "CREATE TABLE IF NOT 
EXISTS %s (spec_uri VARCHAR(" + FlowSpec.Utils.maxFlowSpecUriLength()

Review comment:
       Actually maybe let's avoid referring to 
`FlowSpec.Utils.maxFlowSpecUriLength()` since it's computed based on max 
`flowGroup` and `flowName` size, and it's probably larger than necessary. I 
think we could just directly set this to be `VARCHAR(128)`, currently all the 
topologies we have are 10-20 chars.

##########
File path: 
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/spec_store/MysqlNonFlowSpecStore.java
##########
@@ -0,0 +1,318 @@
+/*
+ * 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.gobblin.runtime.spec_store;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import com.google.common.io.ByteStreams;
+import com.typesafe.config.Config;
+
+import javax.sql.DataSource;
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.broker.SharedResourcesBrokerFactory;
+import org.apache.gobblin.configuration.ConfigurationKeys;
+import org.apache.gobblin.metastore.MysqlDataSourceFactory;
+import org.apache.gobblin.runtime.api.FlowSpec;
+import org.apache.gobblin.runtime.api.InstrumentedSpecStore;
+import org.apache.gobblin.runtime.api.Spec;
+import org.apache.gobblin.runtime.api.SpecNotFoundException;
+import org.apache.gobblin.runtime.api.SpecSerDe;
+import org.apache.gobblin.runtime.api.SpecSerDeException;
+import org.apache.gobblin.runtime.api.SpecStore;
+
+
+/**
+ * Implementation of {@link SpecStore} that stores specs (other than {@link 
FlowSpec}) in MySQL as a serialized BLOB, per the provided
+ * {@link SpecSerDe}.
+ * Note: versions are unsupported, so the version parameter is ignored in 
methods that have it.
+ *
+ * A tag column is added into implementation to serve certain filtering 
purposes in MySQL-based SpecStore.
+ * For example, in DR mode of GaaS, we would only want certain {@link Spec}s 
to be eligible for orchestrated
+ * by alternative GaaS instances. Another example is 
allow-listing/deny-listing {@link Spec}s temporarily
+ * but not removing it from {@link SpecStore}.
+ *
+ * The {@link MysqlSpecStore} is a specialization enhanced for {@link 
FlowSpec} search and retrieval.
+ */
+@Slf4j
+public class MysqlNonFlowSpecStore extends InstrumentedSpecStore {

Review comment:
       There's nothing stopping this class from being used to store flowSpecs 
right? And maybe that would be preferable to avoid storing duplicate info if 
the search functionality is not required. So maybe `MysqlBaseSpecStore` as the 
name?




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


Reply via email to