• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ShardMapping类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.mysql.fabric.ShardMapping的典型用法代码示例。如果您正苦于以下问题:Java ShardMapping类的具体用法?Java ShardMapping怎么用?Java ShardMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ShardMapping类属于com.mysql.fabric包,在下文中一共展示了ShardMapping类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: addQueryTable

import com.mysql.fabric.ShardMapping; //导入依赖的package包/类
/**
 * Add a table to the set of tables used for the next query on this connection.
 * This is used for:
 * <ul>
 * <li>Choosing a shard given the tables used</li>
 * <li>Preventing cross-shard queries</li>
 * </ul>
 */
public void addQueryTable(String tableName) throws SQLException {
    ensureNoTransactionInProgress();

    this.currentConnection = null;

    // choose shard mapping if necessary
    if (this.shardMapping == null) {
        if (this.fabricConnection.getShardMapping(this.database, tableName) != null) {
            setShardTable(tableName);
        }
    } else { // make sure we aren't in conflict with the chosen shard mapping
        ShardMapping mappingForTableName = this.fabricConnection.getShardMapping(this.database, tableName);
        if (mappingForTableName != null && !mappingForTableName.equals(this.shardMapping)) {
            throw SQLError.createSQLException("Cross-shard query not allowed", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, null, getExceptionInterceptor(), this);
        }
    }
    this.queryTables.add(tableName);
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:27,代码来源:FabricMySQLConnectionProxy.java


示例2: addQueryTable

import com.mysql.fabric.ShardMapping; //导入依赖的package包/类
/**
 * Add a table to the set of tables used for the next query on this connection.
 * This is used for:
 * <ul>
 * <li>Choosing a shard given the tables used</li>
 * <li>Preventing cross-shard queries</li>
 * </ul>
 */
public void addQueryTable(String tableName) throws SQLException {
    ensureNoTransactionInProgress();

    this.currentConnection = null;

    try {
        // choose shard mapping if necessary
        if (this.shardMapping == null) {
            if (this.fabricConnection.getShardMapping(this.database, tableName) != null) {
                setShardTable(tableName);
            }
        } else { // make sure we aren't in conflict with the chosen shard mapping
            ShardMapping mappingForTableName = this.fabricConnection.getShardMapping(this.database, tableName);
            if (mappingForTableName != null && !mappingForTableName.equals(this.shardMapping)) {
                throw SQLError.createSQLException("Cross-shard query not allowed", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, null, getExceptionInterceptor(),
                        this);
            }
        }
        this.queryTables.add(tableName);
    } catch (FabricCommunicationException ex) {
        throw SQLError.createSQLException("Fabric communication failure.", SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE, ex, getExceptionInterceptor(),
                this);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:FabricMySQLConnectionProxy.java


示例3: testDumpShardMapsAll

import com.mysql.fabric.ShardMapping; //导入依赖的package包/类
/**
 * Test the Client.getShardMaps() without a match pattern (all maps).
 */
public void testDumpShardMapsAll() throws Exception {
    if (!this.isSetForFabricTest) {
        return;
    }
    Set<ShardMapping> shardMappings = this.client.getShardMappings().getData();
    assertEquals(1, shardMappings.size());
    ShardMapping shardMapping = shardMappings.iterator().next();

    assertEquals(1, shardMapping.getShardTables().size());
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:14,代码来源:TestDumpCommands.java


示例4: testHashShardMappingKeyLookup

import com.mysql.fabric.ShardMapping; //导入依赖的package包/类
public void testHashShardMappingKeyLookup() throws Exception {
    final String globalGroupName = "My global group";

    final String lowerBounds[] = new String[] { /* 0 = */"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* 1 = */"66666666666666666666666666666666",
            /* 2 = */"2809A05A22A4A9C1882A580BCC0AD8A6", /* 3 = */"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD" };

    // setup the mapping
    Set<ShardIndex> shardIndices = new HashSet<ShardIndex>();
    int shardId = 0; // shard id's added sequentially increasing from 0
    for (String lowerBound : lowerBounds) {
        ShardIndex i = new ShardIndex(lowerBound, shardId, "server_group_" + shardId);
        shardId++;
        shardIndices.add(i);
    }
    ShardMapping mapping = new HashShardMapping(5000, ShardingType.HASH, globalGroupName, null, shardIndices);

    // test lookups mapping of test value to the group it maps to test values are hashed with MD5 and compared to lowerBounds values
    String testPairs[][] = new String[][] {
            // exact match should be in that shard
            new String[] { "Jess", "server_group_2" }, // hash = 2809a05a22a4a9c1882a580bcc0ad8a6
            new String[] { "x", "server_group_1" }, // hash = 9dd4e461268c8034f5c8564e155c67a6
            new String[] { "X", "server_group_3" }, // hash = 02129bb861061d1a052c592e2dc6b383
            new String[] { "Y", "server_group_2" }, // hash = 57cec4137b614c87cb4e24a3d003a3e0
            new String[] { "g", "server_group_0" }, // hash = b2f5ff47436671b6e533d8dc3614845d
            // leading zeroes
            new String[] { "168", "server_group_3" }, // hash = 006f52e9102a8d3be2fe5614f42ba989
    };

    for (String[] testPair : testPairs) {
        String key = testPair[0];
        String serverGroup = testPair[1];
        assertEquals(serverGroup, mapping.getGroupNameForKey(key));
    }

    // test a random set of values. we should never return null
    for (int i = 0; i < 1000; ++i) {
        assertNotNull(mapping.getGroupNameForKey("" + i));
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:40,代码来源:TestShardMapping.java


示例5: getShardMappings

import com.mysql.fabric.ShardMapping; //导入依赖的package包/类
/**
 * Retrieve a set of complete shard mappings. The returned mappings include all information
 * available about the mapping.
 * 
 * @param shardMappingIdPattern
 *            the shard mapping id to retrieve
 */
public FabricStateResponse<Set<ShardMapping>> getShardMappings(String shardMappingIdPattern) throws FabricCommunicationException {
    int version = 0;
    Object args[] = new Object[] { version, shardMappingIdPattern }; // common to all calls
    Response mapsResponse = errorSafeCallMethod(METHOD_DUMP_SHARD_MAPS, args);
    // use the lowest ttl of all the calls
    long minExpireTimeMillis = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(mapsResponse.getTtl());
    int baseTtl = mapsResponse.getTtl();

    // construct the maps
    Set<ShardMapping> mappings = new HashSet<ShardMapping>();
    for (Map<String, ?> rawMapping : mapsResponse.getResultSet()) {
        int mappingId = (Integer) rawMapping.get(FIELD_MAPPING_ID);
        ShardingType shardingType = ShardingType.valueOf((String) rawMapping.get(FIELD_TYPE_NAME));
        String globalGroupName = (String) rawMapping.get(FIELD_GLOBAL_GROUP_ID);

        FabricStateResponse<Set<ShardTable>> tables = getShardTables(mappingId);
        FabricStateResponse<Set<ShardIndex>> indices = getShardIndices(mappingId);

        if (tables.getExpireTimeMillis() < minExpireTimeMillis) {
            minExpireTimeMillis = tables.getExpireTimeMillis();
        }
        if (indices.getExpireTimeMillis() < minExpireTimeMillis) {
            minExpireTimeMillis = indices.getExpireTimeMillis();
        }

        ShardMapping m = new ShardMappingFactory().createShardMapping(mappingId, shardingType, globalGroupName, tables.getData(), indices.getData());
        mappings.add(m);
    }

    return new FabricStateResponse<Set<ShardMapping>>(mappings, baseTtl, minExpireTimeMillis);
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:39,代码来源:XmlRpcClient.java


示例6: getShardMappings

import com.mysql.fabric.ShardMapping; //导入依赖的package包/类
/**
 * Retrieve a set of complete shard mappings. The returned mappings include all information
 * available about the mapping.
 * 
 * @param shardMappingIdPattern
 *            the shard mapping id to retrieve
 */
public FabricStateResponse<Set<ShardMapping>> getShardMappings(String shardMappingIdPattern) throws FabricCommunicationException {
    int version = 0;
    Object args[] = new Object[] { version, shardMappingIdPattern }; // common to all calls
    Response mapsResponse = errorSafeCallMethod(METHOD_DUMP_SHARD_MAPS, args);
    // use the lowest ttl of all the calls
    long minExpireTimeMillis = System.currentTimeMillis() + (1000 * mapsResponse.getTtl());

    // construct the maps
    Set<ShardMapping> mappings = new HashSet<ShardMapping>();
    for (Map rawMapping : mapsResponse.getResultSet()) {
        int mappingId = (Integer) rawMapping.get(FIELD_MAPPING_ID);
        ShardingType shardingType = ShardingType.valueOf((String) rawMapping.get(FIELD_TYPE_NAME));
        String globalGroupName = (String) rawMapping.get(FIELD_GLOBAL_GROUP_ID);

        FabricStateResponse<Set<ShardTable>> tables = getShardTables(mappingId);
        FabricStateResponse<Set<ShardIndex>> indices = getShardIndices(mappingId);

        if (tables.getExpireTimeMillis() < minExpireTimeMillis) {
            minExpireTimeMillis = tables.getExpireTimeMillis();
        }
        if (indices.getExpireTimeMillis() < minExpireTimeMillis) {
            minExpireTimeMillis = indices.getExpireTimeMillis();
        }

        ShardMapping m = new ShardMappingFactory().createShardMapping(mappingId, shardingType, globalGroupName, tables.getData(), indices.getData());
        mappings.add(m);
    }

    return new FabricStateResponse<Set<ShardMapping>>(mappings, minExpireTimeMillis);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:XmlRpcClient.java


示例7: testDumpShardMapsAll

import com.mysql.fabric.ShardMapping; //导入依赖的package包/类
/**
 * Test the Client.getShardMaps() without a match pattern (all maps).
 */
public void testDumpShardMapsAll() throws Exception {
	Set<ShardMapping> shardMappings = this.client.getShardMappings().getData();
	assertEquals(1, shardMappings.size());
	ShardMapping shardMapping = shardMappings.iterator().next();

	assertEquals(1, shardMapping.getShardTables().size());
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:11,代码来源:TestDumpCommands.java


示例8: addQueryTable

import com.mysql.fabric.ShardMapping; //导入依赖的package包/类
/**
 * Add a table to the set of tables used for the next query on this connection.
 * This is used for:
 * <ul>
 * <li>Choosing a shard given the tables used</li>
 * <li>Preventing cross-shard queries</li>
 * </ul>
 */
public void addQueryTable(String tableName) throws SQLException {
	ensureNoTransactionInProgress();

	this.currentConnection = null;

	try {
		// choose shard mapping if necessary
		if (this.shardMapping == null) {
			if (this.fabricConnection.getShardMapping(this.database, tableName) != null) {
				setShardTable(tableName);
			}
		} else { // make sure we aren't in conflict with the chosen shard mapping
			ShardMapping mappingForTableName = this.fabricConnection.getShardMapping(this.database, tableName);
			if (mappingForTableName != null &&
				!mappingForTableName.equals(this.shardMapping))
				throw SQLError.createSQLException("Cross-shard query not allowed",
												  SQLError.SQL_STATE_ILLEGAL_ARGUMENT,
												  null,
												  getExceptionInterceptor(),
												  this);
		}
		this.queryTables.add(tableName);
	} catch(FabricCommunicationException ex) {
		throw SQLError.createSQLException("Fabric communication failure.",
										  SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE,
										  ex,
										  getExceptionInterceptor(),
										  this);
	}
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:39,代码来源:FabricMySQLConnectionProxy.java


示例9: getShardMappings

import com.mysql.fabric.ShardMapping; //导入依赖的package包/类
/**
 * Retrieve a set of complete shard mappings. The returned mappings include all information
 * available about the mapping.
 * @param shardMappingIdPattern the shard mapping id to retrieve
 */
public FabricStateResponse<Set<ShardMapping>> getShardMappings(String shardMappingIdPattern) throws FabricCommunicationException {
	int version = 0;
	Object args[] = new Object[] {version, shardMappingIdPattern}; // common to all calls
	DumpResponse mapsResponse = callDumpMethod("dump.shard_maps", args);
	// use the lowest ttl of all the calls
	long minExpireTimeMillis = System.currentTimeMillis() + (1000 * mapsResponse.getTtl());

	// construct the maps
	Set<ShardMapping> mappings = new HashSet<ShardMapping>();
	for (List rawMapping : (List<List>) mapsResponse.getReturnValue()) {
		String mappingId = (String)rawMapping.get(0);
		ShardingType shardingType = ShardingType.valueOf((String)rawMapping.get(1));
		String globalGroupName = (String)rawMapping.get(2);

		FabricStateResponse<Set<ShardTable>> tables = getShardTables(mappingId);
		FabricStateResponse<Set<ShardIndex>> indices = getShardIndices(mappingId);

		if (tables.getExpireTimeMillis() < minExpireTimeMillis)
			minExpireTimeMillis = tables.getExpireTimeMillis();
		if (indices.getExpireTimeMillis() < minExpireTimeMillis)
			minExpireTimeMillis = indices.getExpireTimeMillis();

		ShardMapping m = new ShardMappingFactory().createShardMapping(mappingId, shardingType, globalGroupName,
																	  tables.getData(), indices.getData());
		mappings.add(m);
	}

	return new FabricStateResponse<Set<ShardMapping>>(mappings, minExpireTimeMillis);
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:35,代码来源:XmlRpcClient.java


示例10: testDumpShardMapsAll

import com.mysql.fabric.ShardMapping; //导入依赖的package包/类
/**
 * Test the Client.getShardMaps() without a match pattern (all maps).
 */
public void testDumpShardMapsAll() throws Exception {
    Set<ShardMapping> shardMappings = this.client.getShardMappings().getData();
    assertEquals(1, shardMappings.size());
    ShardMapping shardMapping = shardMappings.iterator().next();

    assertEquals(1, shardMapping.getShardTables().size());
}
 
开发者ID:Prometheus-ETSIIT,项目名称:locaviewer,代码行数:11,代码来源:TestDumpCommands.java



注:本文中的com.mysql.fabric.ShardMapping类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FlatFileItemReader类代码示例发布时间:2022-05-21
下一篇:
Java DefaultApi20类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap