Skip to content

PHOENIX-4870 LoggingPhoenixConnection should log metrics when AutoCommit is set to True.#338

Closed
swaroopak wants to merge 1 commit intoapache:4.x-HBase-1.4from
swaroopak:PHOENIX-4870
Closed

PHOENIX-4870 LoggingPhoenixConnection should log metrics when AutoCommit is set to True.#338
swaroopak wants to merge 1 commit intoapache:4.x-HBase-1.4from
swaroopak:PHOENIX-4870

Conversation

@swaroopak
Copy link
Copy Markdown
Contributor

No description provided.

assertTrue("Mutation read metrics for not found for " + tableName1,
mutationReadMetricsMap.get(tableName1).size() > 0);

clearAllTestMetricMaps();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to call this method unless you are checking any metrics after this.
This automatically gets called in @Before

//with executeUpdate() method
// run SELECT to verify read metrics are logged
String query = "SELECT * FROM " + tableName1;
verifyQueryLevelMetricsLogging(query);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Not related to this Jira, but its better to rename this method to upsertRowsAndVerifyQueryLevelMetricsLogging

mutationWriteMetricsMap.size() > 0);
assertTrue("Mutation read metrics for not found for " + tableName1,
mutationReadMetricsMap.get(tableName1).size() > 0);
//with execute() method
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearAllTestMetricMaps() should be called here to ensure we are getting metrics.

}

@Test
public void testPhoenixMetricsLoggedOnAutoCommit() throws Exception {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: testPhoenixMetricsLoggedOnAutoCommit to testPhoenixMetricsLoggedOnAutoCommitTrue

loggedConn.createStatement().executeUpdate(upsertSelect);
// Autocommit is turned on explicitly
// Hence mutation metrics are expected during implicit commit
assertTrue("Mutation write metrics are not logged for " + tableName2,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check specifically for tableName2 in the map.

private void loggingAutoCommitHelper() throws SQLException {
Connection conn = this.getConnection();

if(stmt.getUpdateOperation().isMutation() && conn.getAutoCommit()){
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't conn.getAutoCommit() check sufficient?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up: Is Statement stmt reference needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper function gets called from both execute and executeUpdate. We need Statment reference to distinguish in case of execute

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if its not a mutation and we try logging the metrics (in case of queries)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this piece of code

                        // If transactional, this will move the read pointer forward
                        if (connection.getAutoCommit()) {
                            connection.commit();
                        }

@twdsilva any idea?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in case of executeQuery, metrics get logged. The differentiating function call happens in PhoenixStatement Class. In case of mutation, it directly executes executeMutation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that is needed any more since we start the transaction in MetaDataClient.updateCache

boolean isTransactional = (table!=null && table.isTransactional());
if (isTransactional) {
connection.getMutationState().startTransaction(table.getTransactionProvider());
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of mutation, it directly executes executeMutation

You can also provide a mutation through execute() method call.

PhoenixRuntime.getReadMetricInfoForMutationsSinceLastReset(conn));
PhoenixRuntime.resetMetrics(conn);
}
return;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not needed

Connection conn = this.getConnection();

if(stmt.getUpdateOperation().isMutation() && conn.getAutoCommit()){
phoenixMetricsLog.logWriteMetricsfoForMutationsSinceLastReset(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reuse this piece of code from somewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlikely, but let me check that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can't.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check LoggingPhoenixConnection? It has similar calls multiple times as well. Might be good to refactor this along with it.

@swaroopak swaroopak force-pushed the PHOENIX-4870 branch 6 times, most recently from 74173e6 to d2e62a9 Compare September 5, 2018 21:24
Copy link
Copy Markdown
Member

@karanmehta93 karanmehta93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, Please fix the nits and we can commit this.

super(stmt);
this.phoenixMetricsLog = phoenixMetricsLog;
this.sql = sql;
this.conn = conn;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can you move the init of variables in the same order as function arguments?

}

private void loggingAutoCommitHelper() throws SQLException {
if(conn instanceof LoggingPhoenixConnection && conn.getAutoCommit()){
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
just change the order of conditions
add brackets around conn instanceof LoggingPhoenixConnection
and add spaces before brackets in conditions (applicable everywhere)

public LoggingPhoenixStatement(Connection conn, Statement stmt, PhoenixMetricsLog phoenixMetricsLog) {
super(stmt);
this.phoenixMetricsLog = phoenixMetricsLog;
this.conn = conn;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above.



@Test
public void testPhoenixMetricsLoggedOnAutoCommitTrue() throws Exception {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just add a description of test above as javadoc comment

@swaroopak swaroopak force-pushed the PHOENIX-4870 branch 4 times, most recently from f9ef04a to 0ad3789 Compare September 6, 2018 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants