Re: [PR] [AMORO-3340]: Database based http session store [amoro]
baiyangtx merged PR #3341: URL: https://github.com/apache/amoro/pull/3341 -- 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-unsubscr...@amoro.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [AMORO-3340]: Database based http session store [amoro]
XBaith commented on code in PR #3341: URL: https://github.com/apache/amoro/pull/3341#discussion_r1861554107 ## amoro-ams/src/main/java/org/apache/amoro/server/persistence/converter/Object2ByteArrayConvert.java: ## @@ -31,14 +30,17 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.util.Locale; public class Object2ByteArrayConvert implements TypeHandler { @Override public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { +String dbName = + ps.getConnection().getMetaData().getDatabaseProductName().toLowerCase(Locale.ENGLISH); if (parameter == null) { - if (SqlSessionFactoryProvider.getDbType().equals(AmoroManagementConf.DB_TYPE_POSTGRES)) { + if (dbName.startsWith(AmoroManagementConf.DB_TYPE_POSTGRES)) { Review Comment: I see -- 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-unsubscr...@amoro.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [AMORO-3340]: Database based http session store [amoro]
baiyangtx commented on code in PR #3341: URL: https://github.com/apache/amoro/pull/3341#discussion_r1861471180 ## amoro-ams/src/main/java/org/apache/amoro/server/persistence/converter/Object2ByteArrayConvert.java: ## @@ -31,14 +30,17 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.util.Locale; public class Object2ByteArrayConvert implements TypeHandler { @Override public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { +String dbName = + ps.getConnection().getMetaData().getDatabaseProductName().toLowerCase(Locale.ENGLISH); if (parameter == null) { - if (SqlSessionFactoryProvider.getDbType().equals(AmoroManagementConf.DB_TYPE_POSTGRES)) { + if (dbName.startsWith(AmoroManagementConf.DB_TYPE_POSTGRES)) { Review Comment: It seems that this judgment will still be successful because the "startswith" is used. -- 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-unsubscr...@amoro.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [AMORO-3340]: Database based http session store [amoro]
XBaith commented on code in PR #3341: URL: https://github.com/apache/amoro/pull/3341#discussion_r1859723322 ## amoro-ams/src/main/java/org/apache/amoro/server/persistence/converter/Object2ByteArrayConvert.java: ## @@ -31,14 +30,17 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.util.Locale; public class Object2ByteArrayConvert implements TypeHandler { @Override public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { +String dbName = + ps.getConnection().getMetaData().getDatabaseProductName().toLowerCase(Locale.ENGLISH); if (parameter == null) { - if (SqlSessionFactoryProvider.getDbType().equals(AmoroManagementConf.DB_TYPE_POSTGRES)) { + if (dbName.startsWith(AmoroManagementConf.DB_TYPE_POSTGRES)) { Review Comment: the lower case `postgresql` is also not equails to `postgres` -- 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-unsubscr...@amoro.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [AMORO-3340]: Database based http session store [amoro]
baiyangtx commented on code in PR #3341: URL: https://github.com/apache/amoro/pull/3341#discussion_r1858553998 ## amoro-ams/src/main/java/org/apache/amoro/server/persistence/converter/Object2ByteArrayConvert.java: ## @@ -31,14 +30,17 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.util.Locale; public class Object2ByteArrayConvert implements TypeHandler { @Override public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { +String dbName = + ps.getConnection().getMetaData().getDatabaseProductName().toLowerCase(Locale.ENGLISH); if (parameter == null) { - if (SqlSessionFactoryProvider.getDbType().equals(AmoroManagementConf.DB_TYPE_POSTGRES)) { + if (dbName.startsWith(AmoroManagementConf.DB_TYPE_POSTGRES)) { Review Comment: The dbName has been converted to lower case. -- 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-unsubscr...@amoro.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [AMORO-3340]: Database based http session store [amoro]
baiyangtx commented on code in PR #3341: URL: https://github.com/apache/amoro/pull/3341#discussion_r1858546054 ## amoro-ams/src/main/java/org/apache/amoro/server/persistence/converter/Object2ByteArrayConvert.java: ## @@ -31,14 +30,17 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.util.Locale; public class Object2ByteArrayConvert implements TypeHandler { @Override public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { +String dbName = + ps.getConnection().getMetaData().getDatabaseProductName().toLowerCase(Locale.ENGLISH); if (parameter == null) { - if (SqlSessionFactoryProvider.getDbType().equals(AmoroManagementConf.DB_TYPE_POSTGRES)) { + if (dbName.startsWith(AmoroManagementConf.DB_TYPE_POSTGRES)) { Review Comment: I referred to the implementation of Jetty. https://github.com/jetty/jetty.project/blob/7f611622f6f821b4c55930939c85444d765165f4/jetty-core/jetty-session/src/main/java/org/eclipse/jetty/session/DatabaseAdaptor.java#L85 This is exactly the framework that Javalin relies on. I inherited this class, but only modified the table names and field names. ## amoro-ams/src/main/java/org/apache/amoro/server/persistence/converter/Object2ByteArrayConvert.java: ## @@ -31,14 +30,17 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.util.Locale; public class Object2ByteArrayConvert implements TypeHandler { @Override public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { +String dbName = + ps.getConnection().getMetaData().getDatabaseProductName().toLowerCase(Locale.ENGLISH); if (parameter == null) { - if (SqlSessionFactoryProvider.getDbType().equals(AmoroManagementConf.DB_TYPE_POSTGRES)) { + if (dbName.startsWith(AmoroManagementConf.DB_TYPE_POSTGRES)) { Review Comment: I referred to the implementation of Jetty. https://github.com/jetty/jetty.project/blob/7f611622f6f821b4c55930939c85444d765165f4/jetty-core/jetty-session/src/main/java/org/eclipse/jetty/session/DatabaseAdaptor.java#L85 This is exactly the framework that Javalin relies on. I inherited this class, but only modified the table names and field names. -- 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-unsubscr...@amoro.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [AMORO-3340]: Database based http session store [amoro]
baiyangtx commented on code in PR #3341: URL: https://github.com/apache/amoro/pull/3341#discussion_r1858546760 ## amoro-ams/src/main/java/org/apache/amoro/server/persistence/converter/Object2ByteArrayConvert.java: ## @@ -31,14 +30,17 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.util.Locale; public class Object2ByteArrayConvert implements TypeHandler { @Override public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { +String dbName = + ps.getConnection().getMetaData().getDatabaseProductName().toLowerCase(Locale.ENGLISH); if (parameter == null) { - if (SqlSessionFactoryProvider.getDbType().equals(AmoroManagementConf.DB_TYPE_POSTGRES)) { + if (dbName.startsWith(AmoroManagementConf.DB_TYPE_POSTGRES)) { Review Comment: I referred to the implementation of Jetty. https://github.com/jetty/jetty.project/blob/7f611622f6f821b4c55930939c85444d765165f4/jetty-core/jetty-session/src/main/java/org/eclipse/jetty/session/DatabaseAdaptor.java#L85 This is exactly the framework that Javalin relies on. I inherited this class, but only modified the table names and field names. ## amoro-ams/src/main/java/org/apache/amoro/server/persistence/converter/Object2ByteArrayConvert.java: ## @@ -31,14 +30,17 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.util.Locale; public class Object2ByteArrayConvert implements TypeHandler { @Override public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { +String dbName = + ps.getConnection().getMetaData().getDatabaseProductName().toLowerCase(Locale.ENGLISH); if (parameter == null) { - if (SqlSessionFactoryProvider.getDbType().equals(AmoroManagementConf.DB_TYPE_POSTGRES)) { + if (dbName.startsWith(AmoroManagementConf.DB_TYPE_POSTGRES)) { Review Comment: I referred to the implementation of Jetty. https://github.com/jetty/jetty.project/blob/7f611622f6f821b4c55930939c85444d765165f4/jetty-core/jetty-session/src/main/java/org/eclipse/jetty/session/DatabaseAdaptor.java#L85 This is exactly the framework that Javalin relies on. I inherited this class, but only modified the table names and field names. -- 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-unsubscr...@amoro.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [AMORO-3340]: Database based http session store [amoro]
baiyangtx commented on code in PR #3341: URL: https://github.com/apache/amoro/pull/3341#discussion_r1858534001 ## amoro-ams/src/main/java/org/apache/amoro/server/persistence/HttpSessionHandlerFactory.java: ## @@ -0,0 +1,90 @@ +/* + * 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.amoro.server.persistence; + +import org.apache.amoro.config.Configurations; +import org.apache.amoro.server.AmoroManagementConf; +import org.eclipse.jetty.server.session.DatabaseAdaptor; +import org.eclipse.jetty.server.session.DefaultSessionCache; +import org.eclipse.jetty.server.session.JDBCSessionDataStore; +import org.eclipse.jetty.server.session.SessionHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sql.DataSource; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; +import java.time.Duration; + +public class HttpSessionHandlerFactory { + private static final Logger LOG = LoggerFactory.getLogger(HttpSessionHandlerFactory.class); + + public static SessionHandler createSessionHandler( + DataSource dataSource, Configurations configurations) { +DatabaseAdaptor adaptor = new DatabaseAdaptor(); +adaptor.setDatasource(dataSource); + +JDBCSessionDataStore dataStore = new JDBCSessionDataStore(); +dataStore.setDatabaseAdaptor(adaptor); +dataStore.setSessionTableSchema(new AmoroSessionTableSchema(dataSource)); + +SessionHandler handler = new SessionHandler(); +DefaultSessionCache cache = new DefaultSessionCache(handler); +cache.setSessionDataStore(dataStore); +// set session timeout +Duration sessionTimeout = configurations.get(AmoroManagementConf.HTTP_SERVER_SESSION_TIMEOUT); +handler.setMaxInactiveInterval((int) sessionTimeout.getSeconds()); Review Comment: yes -- 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-unsubscr...@amoro.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [AMORO-3340]: Database based http session store [amoro]
XBaith commented on code in PR #3341: URL: https://github.com/apache/amoro/pull/3341#discussion_r1858160900 ## amoro-ams/src/main/java/org/apache/amoro/server/persistence/converter/Object2ByteArrayConvert.java: ## @@ -31,14 +30,17 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.util.Locale; public class Object2ByteArrayConvert implements TypeHandler { @Override public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { +String dbName = + ps.getConnection().getMetaData().getDatabaseProductName().toLowerCase(Locale.ENGLISH); if (parameter == null) { - if (SqlSessionFactoryProvider.getDbType().equals(AmoroManagementConf.DB_TYPE_POSTGRES)) { + if (dbName.startsWith(AmoroManagementConf.DB_TYPE_POSTGRES)) { Review Comment: I check source code and i find it's `PostgreSQL` in `org.postgresql.jdbc.PgDatabaseMetaData` that is not equails to `postgres` ## amoro-ams/src/main/java/org/apache/amoro/server/persistence/HttpSessionHandlerFactory.java: ## @@ -0,0 +1,90 @@ +/* + * 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.amoro.server.persistence; + +import org.apache.amoro.config.Configurations; +import org.apache.amoro.server.AmoroManagementConf; +import org.eclipse.jetty.server.session.DatabaseAdaptor; +import org.eclipse.jetty.server.session.DefaultSessionCache; +import org.eclipse.jetty.server.session.JDBCSessionDataStore; +import org.eclipse.jetty.server.session.SessionHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sql.DataSource; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; +import java.time.Duration; + +public class HttpSessionHandlerFactory { + private static final Logger LOG = LoggerFactory.getLogger(HttpSessionHandlerFactory.class); + + public static SessionHandler createSessionHandler( + DataSource dataSource, Configurations configurations) { +DatabaseAdaptor adaptor = new DatabaseAdaptor(); +adaptor.setDatasource(dataSource); + +JDBCSessionDataStore dataStore = new JDBCSessionDataStore(); +dataStore.setDatabaseAdaptor(adaptor); +dataStore.setSessionTableSchema(new AmoroSessionTableSchema(dataSource)); + +SessionHandler handler = new SessionHandler(); +DefaultSessionCache cache = new DefaultSessionCache(handler); +cache.setSessionDataStore(dataStore); +// set session timeout +Duration sessionTimeout = configurations.get(AmoroManagementConf.HTTP_SERVER_SESSION_TIMEOUT); +handler.setMaxInactiveInterval((int) sessionTimeout.getSeconds()); Review Comment: New to Javalin, Is that means we need to re-login after `max_inactive_interval`? -- 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-unsubscr...@amoro.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [AMORO-3340]: Database based http session store [amoro]
codecov-commenter commented on PR #3341: URL: https://github.com/apache/amoro/pull/3341#issuecomment-2499985870 ## [Codecov](https://app.codecov.io/gh/apache/amoro/pull/3341?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report Attention: Patch coverage is `76.03306%` with `29 lines` in your changes missing coverage. Please review. > Project coverage is 27.48%. Comparing base [(`243d289`)](https://app.codecov.io/gh/apache/amoro/commit/243d2894c6bbba59b74be97a1ea93f935f0bd9ad?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`eed6c9e`)](https://app.codecov.io/gh/apache/amoro/commit/eed6c9eeef46006472df14f21cc893a55242af94?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache). > Report is 5 commits behind head on master. | [Files with missing lines](https://app.codecov.io/gh/apache/amoro/pull/3341?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines | |---|---|---| | [...he/amoro/server/persistence/DataSourceFactory.java](https://app.codecov.io/gh/apache/amoro/pull/3341?src=pr&el=tree&filepath=amoro-ams%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Famoro%2Fserver%2Fpersistence%2FDataSourceFactory.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-YW1vcm8tYW1zL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9hbW9yby9zZXJ2ZXIvcGVyc2lzdGVuY2UvRGF0YVNvdXJjZUZhY3RvcnkuamF2YQ==) | 63.01% | [19 Missing and 8 partials :warning: ](https://app.codecov.io/gh/apache/amoro/pull/3341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | | [.../server/persistence/HttpSessionHandlerFactory.java](https://app.codecov.io/gh/apache/amoro/pull/3341?src=pr&el=tree&filepath=amoro-ams%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Famoro%2Fserver%2Fpersistence%2FHttpSessionHandlerFactory.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-YW1vcm8tYW1zL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9hbW9yby9zZXJ2ZXIvcGVyc2lzdGVuY2UvSHR0cFNlc3Npb25IYW5kbGVyRmFjdG9yeS5qYXZh) | 97.22% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/amoro/pull/3341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | | [...persistence/converter/Object2ByteArrayConvert.java](https://app.codecov.io/gh/apache/amoro/pull/3341?src=pr&el=tree&filepath=amoro-ams%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Famoro%2Fserver%2Fpersistence%2Fconverter%2FObject2ByteArrayConvert.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-YW1vcm8tYW1zL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9hbW9yby9zZXJ2ZXIvcGVyc2lzdGVuY2UvY29udmVydGVyL09iamVjdDJCeXRlQXJyYXlDb252ZXJ0LmphdmE=) | 66.66% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/amoro/pull/3341?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Additional details and impacted files ```diff @@ Coverage Diff @@ ## master#3341 +/- ## + Coverage 21.59% 27.48% +5.88% - Complexity 2309 3509+1200 Files 426 593 +167 Lines 3971948295+8576 Branches 5624 6231 +607 + Hits 857713272+4695 - Misses3041434087+3673 - Partials728 936 +208 ``` | [Flag](https://app.codecov.io/gh/apache/amoro/pull/3341/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | |---|---|---| | [core](https://app.codecov.io/gh/apache/amoro/pull/3341/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `27.48% <76.03%> (?)` | | | [trino](https://app.codecov.io/gh/apache/amoro/pull/3341/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more. [:umbrella: View full report in Codecov by Sentry](https://app.code
Re: [PR] [AMORO-3340]: Database based http session store [amoro]
baiyangtx commented on PR #3341: URL: https://github.com/apache/amoro/pull/3341#issuecomment-2493049838 After login, we can find session info in amoro sysdb. ![image](https://github.com/user-attachments/assets/36a4d76c-6c15-4c88-b3dd-d1acc160490c) -- 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-unsubscr...@amoro.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org