gobblin-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Work logged] (GOBBLIN-768) Add MySQL implementation of SpecStore
Date Sat, 11 May 2019 01:17:00 GMT

     [ https://issues.apache.org/jira/browse/GOBBLIN-768?focusedWorklogId=240530&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-240530
]

ASF GitHub Bot logged work on GOBBLIN-768:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 11/May/19 01:16
            Start Date: 11/May/19 01:16
    Worklog Time Spent: 10m 
      Work Description: jhsenjaliya commented on pull request #2631: [GOBBLIN-768] Add MySQL
implementation of SpecStore
URL: https://github.com/apache/incubator-gobblin/pull/2631#discussion_r283077050
 
 

 ##########
 File path: gobblin-runtime/src/main/java/org/apache/gobblin/runtime/spec_store/MysqlSpecStore.java
 ##########
 @@ -0,0 +1,215 @@
+/*
+ * 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.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+import java.sql.Blob;
+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.typesafe.config.Config;
+
+import javax.sql.DataSource;
+
+import org.apache.gobblin.broker.SharedResourcesBrokerFactory;
+import org.apache.gobblin.configuration.ConfigurationKeys;
+import org.apache.gobblin.metastore.MysqlDataSourceFactory;
+import org.apache.gobblin.runtime.api.Spec;
+import org.apache.gobblin.runtime.api.SpecNotFoundException;
+import org.apache.gobblin.runtime.api.SpecStore;
+
+
+/**
+ * Implementation of {@link SpecStore} that stores specs as serialized java objects in MySQL.
Note that versions are not
+ * supported, so the version parameter will be ignored in methods that have it.
+ */
+public class MysqlSpecStore implements SpecStore {
+  private static final String CREATE_TABLE_STATEMENT =
+      "CREATE TABLE IF NOT EXISTS %s (spec_uri VARCHAR(128) NOT NULL, spec LONGBLOB, PRIMARY
KEY (spec_uri))";
+  private static final String EXISTS_STATEMENT = "SELECT EXISTS(SELECT * FROM %s WHERE spec_uri
= ?)";
+  private static final String INSERT_STATEMENT = "INSERT INTO %s (spec_uri, 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 = "SELECT spec FROM %s WHERE spec_uri = ?";
+  private static final String GET_ALL_STATEMENT = "SELECT spec_uri, spec FROM %s";
+
+  private DataSource dataSource;
+  private String tableName;
+  private URI specStoreURI;
+
+  public MysqlSpecStore(Config config) throws IOException {
+    this.dataSource = MysqlDataSourceFactory.get(config, SharedResourcesBrokerFactory.getImplicitBroker());
+    this.tableName = config.getString(ConfigurationKeys.STATE_STORE_DB_TABLE_KEY);
+    this.specStoreURI = URI.create(config.getString(ConfigurationKeys.STATE_STORE_DB_URL_KEY));
+    try (Connection connection = this.dataSource.getConnection();
+        PreparedStatement statement = connection.prepareStatement(String.format(CREATE_TABLE_STATEMENT,
this.tableName))) {
+      statement.executeUpdate();
+    } catch (SQLException e) {
+      throw new IOException(e);
+    }
+  }
+
+  @Override
+  public boolean exists(URI specUri) throws IOException {
+    try (Connection connection = this.dataSource.getConnection();
+        PreparedStatement statement = connection.prepareStatement(String.format(EXISTS_STATEMENT,
this.tableName))) {
+      statement.setString(1, specUri.toString());
+      ResultSet rs = statement.executeQuery();
+      rs.next();
+      return rs.getBoolean(1);
+    } catch (SQLException e) {
+      throw new IOException(e);
+    }
+  }
+
+  @Override
+  public void addSpec(Spec spec) throws IOException {
+    try (Connection connection = this.dataSource.getConnection();
+        PreparedStatement statement = connection.prepareStatement(String.format(INSERT_STATEMENT,
this.tableName));
+        ByteArrayOutputStream aos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(aos)) {
+
+      oos.writeObject(spec);
 
 Review comment:
   should this generate same bytes as SpecSerDe.serialize ?
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 240530)
    Time Spent: 0.5h  (was: 20m)

> Add MySQL implementation of SpecStore
> -------------------------------------
>
>                 Key: GOBBLIN-768
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-768
>             Project: Apache Gobblin
>          Issue Type: New Feature
>            Reporter: Jack Moseley
>            Priority: Major
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message