Skip to content

Commit d5a45a4

Browse files
committed
[HWORKS-734] Remove jdbc pool when initializing online feature store … (logicalclocks#1545)
* [HWORKS-734] Remove jdbc pool when initializing online feature store database for project * Revert changes to hopsworks-common pom.xml * Fix initialization of the jdbcString variable
1 parent 826a161 commit d5a45a4

File tree

8 files changed

+301
-349
lines changed

8 files changed

+301
-349
lines changed

hopsworks-common/src/main/java/io/hops/hopsworks/common/featurestore/FeaturestoreController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.hops.hopsworks.common.featurestore.featureview.FeatureViewFacade;
2323
import io.hops.hopsworks.common.featurestore.online.OnlineFeaturestoreController;
2424
import io.hops.hopsworks.common.featurestore.featuregroup.FeaturegroupFacade;
25+
import io.hops.hopsworks.common.featurestore.online.OnlineFeaturestoreFacade;
2526
import io.hops.hopsworks.common.featurestore.storageconnectors.FeaturestoreConnectorFacade;
2627
import io.hops.hopsworks.common.featurestore.storageconnectors.FeaturestoreStorageConnectorController;
2728
import io.hops.hopsworks.common.featurestore.storageconnectors.FeaturestoreStorageConnectorDTO;
@@ -80,6 +81,8 @@ public class FeaturestoreController {
8081
@EJB
8182
private OnlineFeaturestoreController onlineFeaturestoreController;
8283
@EJB
84+
private OnlineFeaturestoreFacade onlineFeaturestoreFacade;
85+
@EJB
8386
private HiveController hiveController;
8487
@EJB
8588
private FeaturegroupFacade featuregroupFacade;
@@ -375,8 +378,7 @@ private FeaturestoreDTO convertFeaturestoreToDTO(Featurestore featurestore) {
375378
if (settings.isOnlineFeaturestore() &&
376379
onlineFeaturestoreController.checkIfDatabaseExists(
377380
onlineFeaturestoreController.getOnlineFeaturestoreDbName(featurestore.getProject()))) {
378-
featurestoreDTO.setMysqlServerEndpoint(onlineFeaturestoreController.getJdbcURL());
379-
featurestoreDTO.setOnlineFeaturestoreSize(onlineFeaturestoreController.getDbSize(featurestore));
381+
featurestoreDTO.setMysqlServerEndpoint(onlineFeaturestoreFacade.getJdbcURL());
380382
featurestoreDTO.setOnlineFeaturestoreName(featurestore.getProject().getName());
381383
featurestoreDTO.setOnlineEnabled(true);
382384
}

hopsworks-common/src/main/java/io/hops/hopsworks/common/featurestore/FeaturestoreDTO.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public class FeaturestoreDTO {
3535
private String projectName;
3636
private Integer projectId;
3737
private String onlineFeaturestoreName;
38-
private Double onlineFeaturestoreSize;
3938
private String offlineFeaturestoreName;
4039
private String hiveEndpoint;
4140
private String mysqlServerEndpoint;
@@ -58,7 +57,6 @@ public FeaturestoreDTO(Featurestore featurestore) {
5857
this.offlineFeaturestoreName = null;
5958
this.hiveEndpoint = null;
6059
this.mysqlServerEndpoint = null;
61-
this.onlineFeaturestoreSize = 0.0;
6260
this.onlineEnabled = false;
6361
}
6462

@@ -104,16 +102,7 @@ public String getOfflineFeaturestoreName() {
104102
public void setOfflineFeaturestoreName(String offlineFeaturestoreName) {
105103
this.offlineFeaturestoreName = offlineFeaturestoreName;
106104
}
107-
108-
@XmlElement
109-
public Double getOnlineFeaturestoreSize() {
110-
return onlineFeaturestoreSize;
111-
}
112-
113-
public void setOnlineFeaturestoreSize(Double onlineFeaturestoreSize) {
114-
this.onlineFeaturestoreSize = onlineFeaturestoreSize;
115-
}
116-
105+
117106
@XmlElement
118107
public String getHiveEndpoint() {
119108
return hiveEndpoint;
@@ -186,7 +175,6 @@ public String toString() {
186175
", projectName='" + projectName + '\'' +
187176
", projectId=" + projectId +
188177
", onlineFeaturestoreName='" + onlineFeaturestoreName + '\'' +
189-
", onlineFeaturestoreSize=" + onlineFeaturestoreSize +
190178
", offlineFeaturestoreName='" + offlineFeaturestoreName + '\'' +
191179
", hiveEndpoint='" + hiveEndpoint + '\'' +
192180
", mysqlServerEndpoint='" + mysqlServerEndpoint + '\'' +

hopsworks-common/src/main/java/io/hops/hopsworks/common/featurestore/featuregroup/cached/CachedFeaturegroupController.java

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import org.apache.calcite.sql.dialect.HiveSqlDialect;
6363
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
6464
import org.apache.calcite.sql.parser.SqlParserPos;
65-
import org.javatuples.Pair;
6665

6766
import javax.annotation.PostConstruct;
6867
import javax.ejb.EJB;
@@ -74,7 +73,6 @@
7473
import java.sql.Connection;
7574
import java.sql.DriverManager;
7675
import java.sql.ResultSet;
77-
import java.sql.ResultSetMetaData;
7876
import java.sql.SQLException;
7977
import java.sql.Statement;
8078
import java.util.ArrayList;
@@ -371,43 +369,6 @@ public void deleteFeatureGroup(Featuregroup featuregroup, Project project, Users
371369
cachedFeatureGroupFacade.remove(featuregroup.getCachedFeaturegroup());
372370
}
373371

374-
/**
375-
* Parses a ResultSet from a Hive query into a list of RowValueQueryResultDTOs
376-
*
377-
* @param rs resultset to parse
378-
* @return list of parsed rows
379-
* @throws SQLException
380-
*/
381-
public FeaturegroupPreview parseResultset(ResultSet rs) throws SQLException {
382-
ResultSetMetaData rsmd = rs.getMetaData();
383-
FeaturegroupPreview featuregroupPreview = new FeaturegroupPreview();
384-
385-
while (rs.next()) {
386-
FeaturegroupPreview.Row row = new FeaturegroupPreview.Row();
387-
388-
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
389-
Object columnValue = rs.getObject(i);
390-
row.addValue(new Pair<>(parseColumnLabel(rsmd.getColumnLabel(i)),
391-
columnValue == null ? null : columnValue.toString()));
392-
}
393-
featuregroupPreview.addRow(row);
394-
}
395-
396-
return featuregroupPreview;
397-
}
398-
399-
/**
400-
* Column labels contain the table name as well. Remove it
401-
* @param columnLabel
402-
* @return
403-
*/
404-
private String parseColumnLabel(String columnLabel) {
405-
if (columnLabel.contains(".")) {
406-
return columnLabel.split("\\.")[1];
407-
}
408-
return columnLabel;
409-
}
410-
411372
/**
412373
* Opens a JDBC connection to HS2 using the given database and project-user and then executes a regular
413374
* SQL query
@@ -430,7 +391,7 @@ private FeaturegroupPreview executeReadHiveQuery(String query, String databaseNa
430391
conn = initConnection(databaseName, project, user);
431392
stmt = conn.createStatement();
432393
ResultSet rs = stmt.executeQuery(query);
433-
return parseResultset(rs);
394+
return featurestoreUtils.parseResultset(rs);
434395
} catch (SQLException e) {
435396
//Hive throws a generic HiveSQLException not a specific AuthorizationException
436397
if (e.getMessage().toLowerCase().contains("permission denied")) {

hopsworks-common/src/main/java/io/hops/hopsworks/common/featurestore/featuregroup/online/OnlineFeaturegroupController.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import io.hops.hopsworks.common.dao.kafka.TopicDTO;
2222
import io.hops.hopsworks.common.featurestore.feature.FeatureGroupFeatureDTO;
2323
import io.hops.hopsworks.common.featurestore.featuregroup.FeaturegroupController;
24-
import io.hops.hopsworks.common.featurestore.featuregroup.cached.CachedFeaturegroupController;
2524
import io.hops.hopsworks.common.featurestore.featuregroup.cached.FeaturegroupPreview;
2625
import io.hops.hopsworks.common.featurestore.online.OnlineFeaturestoreController;
2726
import io.hops.hopsworks.common.featurestore.online.OnlineFeaturestoreFacade;
@@ -93,8 +92,6 @@ public class OnlineFeaturegroupController {
9392
@EJB
9493
private ProjectController projectController;
9594
@EJB
96-
private CachedFeaturegroupController cachedFeaturegroupController;
97-
@EJB
9895
private ConstructorController constructorController;
9996
@EJB
10097
private FeaturegroupController featuregroupController;
@@ -120,27 +117,26 @@ protected OnlineFeaturegroupController(Settings settings) {
120117
* @throws SQLException
121118
* @throws FeaturestoreException
122119
*/
123-
public void dropMySQLTable(Featuregroup featuregroup, Project project, Users user) throws SQLException,
124-
FeaturestoreException {
120+
public void dropMySQLTable(Featuregroup featuregroup, Project project, Users user) throws FeaturestoreException {
125121
//Drop data table
126122
String query = "DROP TABLE " + featuregroup.getName() + "_" + featuregroup.getVersion() + ";";
127-
onlineFeaturestoreController.executeUpdateJDBCQuery(query,
123+
onlineFeaturestoreFacade.executeUpdateJDBCQuery(query,
128124
onlineFeaturestoreController.getOnlineFeaturestoreDbName(featuregroup.getFeaturestore().getProject()),
129125
project, user);
130126
}
131127

132128
public void createMySQLTable(Featurestore featurestore, String tableName, List<FeatureGroupFeatureDTO> features,
133129
Project project, Users user)
134-
throws FeaturestoreException, SQLException{
130+
throws FeaturestoreException {
135131
String dbName = onlineFeaturestoreController.getOnlineFeaturestoreDbName(featurestore.getProject());
136132
String createStatement = buildCreateStatement(dbName, tableName, features);
137-
onlineFeaturestoreController.executeUpdateJDBCQuery(createStatement, dbName, project, user);
133+
onlineFeaturestoreFacade.executeUpdateJDBCQuery(createStatement, dbName, project, user);
138134
}
139135

140136
public void setupOnlineFeatureGroup(Featurestore featureStore, Featuregroup featureGroup,
141137
List<FeatureGroupFeatureDTO> features, Project project, Users user)
142-
throws KafkaException, SchemaException, ProjectException, FeaturestoreException, SQLException,
143-
IOException, HopsSecurityException, ServiceException {
138+
throws KafkaException, SchemaException, ProjectException, FeaturestoreException, IOException,
139+
HopsSecurityException, ServiceException {
144140
// check if onlinefs user is part of project
145141
if (project.getProjectTeamCollection().stream().noneMatch(pt ->
146142
pt.getUser().getUsername().equals(OnlineFeaturestoreController.ONLINEFS_USERNAME))) {
@@ -163,7 +159,7 @@ public void setupOnlineFeatureGroup(Featurestore featureStore, Featuregroup feat
163159
// The topic schema is registered for each feature group
164160
public void createFeatureGroupKafkaTopic(Project project, Featuregroup featureGroup,
165161
List<FeatureGroupFeatureDTO> features)
166-
throws KafkaException, SchemaException, FeaturestoreException {
162+
throws KafkaException, SchemaException, FeaturestoreException {
167163
String avroSchema = avroSchemaConstructorController.constructSchema(featureGroup, features);
168164
schemasController.validateSchema(project, avroSchema);
169165

@@ -181,7 +177,7 @@ public void createFeatureGroupKafkaTopic(Project project, Featuregroup featureGr
181177
}
182178

183179
public void deleteFeatureGroupKafkaTopic(Project project, Featuregroup featureGroup)
184-
throws KafkaException, SchemaException {
180+
throws KafkaException, SchemaException {
185181
String topicName = Utils.getFeatureGroupTopicName(featureGroup);
186182
String featureGroupEntityName = Utils.getFeaturegroupName(featureGroup);
187183
// user might have deleted topic manually
@@ -291,9 +287,9 @@ public String buildAlterStatement(String tableName, String dbName, List<FeatureG
291287

292288
public void alterMySQLTableColumns(Featurestore featurestore, String tableName,
293289
List<FeatureGroupFeatureDTO> featureDTOs, Project project, Users user)
294-
throws FeaturestoreException, SQLException {
290+
throws FeaturestoreException {
295291
String dbName = onlineFeaturestoreController.getOnlineFeaturestoreDbName(featurestore.getProject());
296-
onlineFeaturestoreController.executeUpdateJDBCQuery(buildAlterStatement(tableName, dbName, featureDTOs), dbName,
292+
onlineFeaturestoreFacade.executeUpdateJDBCQuery(buildAlterStatement(tableName, dbName, featureDTOs), dbName,
297293
project, user);
298294
}
299295

@@ -330,7 +326,7 @@ public String getOnlineType(FeatureGroupFeatureDTO featureGroupFeatureDTO) {
330326
* @throws SQLException
331327
*/
332328
public FeaturegroupPreview getFeaturegroupPreview(Featuregroup featuregroup, Project project, Users user, int limit)
333-
throws FeaturestoreException, SQLException {
329+
throws FeaturestoreException {
334330
String tbl = featuregroupController.getTblName(featuregroup.getName(), featuregroup.getVersion());
335331

336332
List<FeatureGroupFeatureDTO> features = featuregroupController.getFeatures(featuregroup, project, user);
@@ -352,10 +348,10 @@ public FeaturegroupPreview getFeaturegroupPreview(Featuregroup featuregroup, Pro
352348
SqlLiteral.createExactNumeric(String.valueOf(limit), SqlParserPos.ZERO), null);
353349
String db = onlineFeaturestoreController.getOnlineFeaturestoreDbName(featuregroup.getFeaturestore().getProject());
354350
try {
355-
return onlineFeaturestoreController.executeReadJDBCQuery(
351+
return onlineFeaturestoreFacade.executeReadJDBCQuery(
356352
select.toSqlString(new MysqlSqlDialect(SqlDialect.EMPTY_CONTEXT)).getSql(), db, project, user);
357353
} catch(Exception e) {
358-
return onlineFeaturestoreController.executeReadJDBCQuery(
354+
return onlineFeaturestoreFacade.executeReadJDBCQuery(
359355
select.toSqlString(new MysqlSqlDialect(SqlDialect.EMPTY_CONTEXT)).getSql(), db, project, user);
360356
}
361357
}

0 commit comments

Comments
 (0)