io.datarouter.client.mysql.op.read.index.MysqlManagedIndexGetKeyRangesOp Maven / Gradle / Ivy
/*
* Copyright © 2009 HotPads ([email protected])
*
* Licensed 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 io.datarouter.client.mysql.op.read.index;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Collection;
import java.util.List;
import io.datarouter.client.mysql.MysqlClientType;
import io.datarouter.client.mysql.field.codec.factory.MysqlFieldCodecFactory;
import io.datarouter.client.mysql.op.BaseMysqlOp;
import io.datarouter.client.mysql.op.Isolation;
import io.datarouter.client.mysql.sql.MysqlSqlFactory;
import io.datarouter.client.mysql.util.MysqlTool;
import io.datarouter.instrumentation.trace.TracerTool;
import io.datarouter.instrumentation.trace.TracerTool.TraceSpanInfoBuilder;
import io.datarouter.model.databean.Databean;
import io.datarouter.model.index.IndexEntry;
import io.datarouter.model.key.primary.PrimaryKey;
import io.datarouter.model.serialize.fielder.DatabeanFielder;
import io.datarouter.storage.Datarouter;
import io.datarouter.storage.config.Config;
import io.datarouter.storage.node.op.raw.read.IndexedStorageReader;
import io.datarouter.storage.serialize.fieldcache.IndexEntryFieldInfo;
import io.datarouter.storage.serialize.fieldcache.PhysicalDatabeanFieldInfo;
import io.datarouter.storage.util.DatarouterCounters;
import io.datarouter.util.tuple.Range;
public class MysqlManagedIndexGetKeyRangesOp<
PK extends PrimaryKey,
D extends Databean,
F extends DatabeanFielder,
IK extends PrimaryKey,
IE extends IndexEntry,
IF extends DatabeanFielder>
extends BaseMysqlOp>{
private final Collection> ranges;
private final PhysicalDatabeanFieldInfo databeanFieldInfo;
private final MysqlFieldCodecFactory fieldCodecFactory;
private final MysqlSqlFactory mysqlSqlFactory;
private final Config config;
private final IndexEntryFieldInfo indexEntryFieldInfo;
private final MysqlClientType mysqlClientType;
public MysqlManagedIndexGetKeyRangesOp(
Datarouter datarouter,
PhysicalDatabeanFieldInfo databeanFieldInfo,
MysqlFieldCodecFactory fieldCodecFactory,
MysqlSqlFactory mysqlSqlFactory,
IndexEntryFieldInfo indexEntryFieldInfo,
Collection> ranges,
Config config,
MysqlClientType mysqlClientType){
super(datarouter, databeanFieldInfo.getClientId(), Isolation.DEFAULT, true);
this.ranges = ranges;
this.databeanFieldInfo = databeanFieldInfo;
this.fieldCodecFactory = fieldCodecFactory;
this.mysqlSqlFactory = mysqlSqlFactory;
this.config = config;
this.indexEntryFieldInfo = indexEntryFieldInfo;
this.mysqlClientType = mysqlClientType;
}
@Override
public List runOnce(){
String tableName = databeanFieldInfo.getTableName();
String indexName = indexEntryFieldInfo.getIndexName();
String clientName = databeanFieldInfo.getClientId().getName();
String nodeName = databeanFieldInfo.getNodeName() + "." + indexName;
String opName = IndexedStorageReader.OP_getIndexKeyRange;
boolean disableIntroducer = databeanFieldInfo.getDisableIntroducer();
Connection connection = getConnection();
PreparedStatement statement = mysqlSqlFactory
.createSql(getClientId(), tableName, disableIntroducer)
.getInRanges(
tableName,
config,
indexEntryFieldInfo.getPrimaryKeyFields(),
ranges,
indexEntryFieldInfo.getPrimaryKeyFields(),
indexName)
.prepare(connection);
List result = MysqlTool.selectIndexEntryKeys(fieldCodecFactory, indexEntryFieldInfo, statement);
DatarouterCounters.incClientNodeCustom(mysqlClientType, opName + " selects", clientName, nodeName, 1L);
DatarouterCounters.incClientNodeCustom(mysqlClientType, opName + " rows", clientName, nodeName, result.size());
TracerTool.appendToSpanInfo(new TraceSpanInfoBuilder()
.ranges(ranges.size())
.add("indexKeys", result.size()));
return result;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy