下面列出了org.apache.hadoop.mapreduce.split.JobSplit#org.apache.ignite.IgniteException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** {@inheritDoc} */
@Override public int[] backupPartitions(ClusterNode n) {
ctx.gateway().readLock();
try {
Set<Integer> parts = cache().assignment().backupPartitions(n.id());
return U.toIntArray(parts);
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
finally {
ctx.gateway().readUnlock();
}
}
/** {@inheritDoc} */
@Override public Map<ClusterNode, Collection<K>> mapKeysToNodes(@Nullable Collection<? extends K> keys) {
ctx.gateway().readLock();
try {
if (F.isEmpty(keys))
return Collections.emptyMap();
AffinityInfo affInfo = cache();
return affinityMap(affInfo, keys);
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
finally {
ctx.gateway().readUnlock();
}
}
/**
* @param keys Keys.
* @return Values map.
*/
public Map<K, V> getAll(Collection<? extends K> keys) {
IgniteInternalCache<K, V> delegate = getDelegateSafe();
try {
if (isAsync()) {
setFuture(delegate.getAllAsync(keys));
return null;
}
else
return delegate.getAll(keys);
}
catch (IgniteCheckedException | IgniteException e) {
throw cacheException(e);
}
}
/** {@inheritDoc} */
@Override public boolean replace(K key, V val) {
IgniteInternalCache<K, V> delegate = getDelegateSafe();
try {
if (isAsync()) {
setFuture(delegate.replaceAsync(key, val));
return false;
}
else
return delegate.replace(key, val);
}
catch (IgniteCheckedException | IgniteException e) {
throw cacheException(e);
}
}
/**
* Starts streamer.
*
* @throws IgniteException If failed.
*/
@SuppressWarnings("unchecked")
public void start() throws IgniteException {
A.notNull(igniteConfigFile, "Ignite config file");
A.notNull(cacheName, "Cache name");
A.notNull(igniteTupleField, "Ignite tuple field");
setIgnite(StreamerContext.getIgnite());
final IgniteDataStreamer<K, V> dataStreamer = StreamerContext.getStreamer();
dataStreamer.autoFlushFrequency(autoFlushFrequency);
dataStreamer.allowOverwrite(allowOverwrite);
setStreamer(dataStreamer);
log = getIgnite().log();
stopped = false;
}
/** {@inheritDoc} */
@Override public IgniteFuture<UUID> remoteListenAsync(@Nullable Object topic,
IgniteBiPredicate<UUID, ?> p) throws IgniteException {
A.notNull(p, "p");
guard();
try {
GridContinuousHandler hnd = new GridMessageListenHandler(topic, securityAwareBiPredicate(p));
return new IgniteFutureImpl<>(ctx.continuous().startRoutine(hnd,
false,
1,
0,
false,
prj.predicate()));
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
}
finally {
unguard();
}
}
/**
* Sets binary config.
*
* @param igniteCfg Ignite config.
* @param dotNetCfg .NET config.
*/
private void setBinaryConfiguration(IgniteConfiguration igniteCfg, PlatformDotNetConfigurationEx dotNetCfg) {
// Check marshaller.
Marshaller marsh = igniteCfg.getMarshaller();
if (marsh == null) {
igniteCfg.setMarshaller(new BinaryMarshaller());
dotNetCfg.warnings(Collections.singleton("Marshaller is automatically set to " +
BinaryMarshaller.class.getName() + " (other nodes must have the same marshaller type)."));
}
else if (!(marsh instanceof BinaryMarshaller))
throw new IgniteException("Unsupported marshaller (only " + BinaryMarshaller.class.getName() +
" can be used when running Apache Ignite.NET): " + marsh.getClass().getName());
BinaryConfiguration bCfg = igniteCfg.getBinaryConfiguration();
}
/**
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteException If example execution failed.
*/
public static void main(String[] args) throws IgniteException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println();
System.out.println(">>> Entry processor example started.");
// Auto-close cache at the end of the example.
try (IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(CACHE_NAME)) {
// Demonstrates usage of EntryProcessor.invoke(...) method.
populateEntriesWithInvoke(cache);
// Demonstrates usage of EntryProcessor.invokeAll(...) method.
incrementEntriesWithInvokeAll(cache);
}
finally {
// Distributed cache could be removed from cluster only by #destroyCache() call.
ignite.destroyCache(CACHE_NAME);
}
}
}
/**
* @param ctx Checkpoint context.
* @throws IgniteCheckedException If failed.
*/
private void saveReuseListMetadata(Context ctx) throws IgniteCheckedException {
Executor executor = ctx.executor();
if (executor == null)
reuseList.saveMetadata(IoStatisticsHolderNoOp.INSTANCE);
else {
executor.execute(() -> {
try {
reuseList.saveMetadata(IoStatisticsHolderNoOp.INSTANCE);
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
});
}
}
/**
* @param el Element.
* @param paramsCnt Number of parameters.
* @param paramIdxs Parameter indexes.
*/
private static void findParams(@Nullable GridSqlAst el, int paramsCnt, TreeSet<Integer> paramIdxs) {
if (el == null)
return;
if (el instanceof GridSqlParameter) {
// H2 Supports queries like "select ?5" but first 4 non-existing parameters are need to be set to any value.
// Here we will set them to NULL.
final int idx = ((GridSqlParameter)el).index();
if (paramsCnt <= idx)
throw new IgniteException("Invalid number of query parameters. " +
"Cannot find " + idx + " parameter.");
paramIdxs.add(idx);
}
else if (el instanceof GridSqlSubquery)
findParamsQuery(((GridSqlSubquery)el).subquery(), paramsCnt, paramIdxs);
else {
for (int i = 0; i < el.size(); i++)
findParams(el.child(i), paramsCnt, paramIdxs);
}
}
/** {@inheritDoc} */
@Nullable @Override public Object execute() {
BinaryObjectEx arg0 = ((BinaryObjectEx)arg);
BinaryType meta = ignite.binary().type(arg0.typeId());
if (meta == null)
throw new IgniteException("Metadata doesn't exist.");
if (meta.fieldNames() == null || !meta.fieldNames().contains("Field"))
throw new IgniteException("Field metadata doesn't exist.");
if (!F.eq("int", meta.fieldTypeName("Field")))
throw new IgniteException("Invalid field type: " + meta.fieldTypeName("Field"));
if (meta.affinityKeyFieldName() != null)
throw new IgniteException("Unexpected affinity key: " + meta.affinityKeyFieldName());
return arg0.field("field");
}
/** {@inheritDoc} */
@Override public int[] primaryPartitions(ClusterNode n) {
ctx.gateway().readLock();
try {
Set<Integer> parts = cache().assignment().primaryPartitions(n.id());
return U.toIntArray(parts);
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
finally {
ctx.gateway().readUnlock();
}
}
/** {@inheritDoc} */
@Override public Boolean mkdirs(final IgfsPath path, final Map<String, String> props)
throws IgniteCheckedException {
try {
IgfsUserContext.doAs(user, new IgniteOutClosure<Void>() {
@Override public Void apply() {
igfs.mkdirs(path, props);
return null;
}
});
return true;
}
catch (IgniteException e) {
throw new IgniteCheckedException(e);
}
catch (IllegalStateException ignored) {
throw new HadoopIgfsCommunicationException("Failed to findIgfsAndCreate directory because Grid is stopping: " +
path);
}
}
/** {@inheritDoc} */
@Override public void onReadyForRead(ReadOnlyMetastorage metastorage) {
synchronized (metaStorageMux) {
if (durableBackgroundTasks.isEmpty()) {
try {
metastorage.iterate(
STORE_DURABLE_BACKGROUND_TASK_PREFIX,
(key, val) -> durableBackgroundTasks.put(key, (DurableBackgroundTask)val),
true
);
}
catch (IgniteCheckedException e) {
throw new IgniteException("Failed to iterate durable background tasks storage.", e);
}
}
}
}
/**
* Verifies all nodes in current cluster topology support BaselineTopology feature so compatibilityMode flag is
* enabled to reset.
*
* @param discoCache
*/
private void verifyBaselineTopologySupport(DiscoCache discoCache) {
if (discoCache.minimumServerNodeVersion().compareTo(MIN_BLT_SUPPORTING_VER) < 0) {
SB sb = new SB("Cluster contains nodes that don't support BaselineTopology: [");
for (ClusterNode cn : discoCache.serverNodes()) {
if (cn.version().compareTo(MIN_BLT_SUPPORTING_VER) < 0)
sb
.a("[")
.a(cn.consistentId())
.a(":")
.a(cn.version())
.a("], ");
}
sb.d(sb.length() - 2, sb.length());
throw new IgniteException(sb.a("]").toString());
}
}
/**
* Validates service configuration.
*
* @param c Service configuration.
* @throws IgniteException If validation failed.
*/
private void validate(ServiceConfiguration c) throws IgniteException {
IgniteConfiguration cfg = ctx.config();
DeploymentMode depMode = cfg.getDeploymentMode();
if (cfg.isPeerClassLoadingEnabled() && (depMode == PRIVATE || depMode == ISOLATED))
throw new IgniteException("Cannot deploy services in PRIVATE or ISOLATED deployment mode: " + depMode);
ensure(c.getName() != null, "getName() != null", null);
ensure(c.getTotalCount() >= 0, "getTotalCount() >= 0", c.getTotalCount());
ensure(c.getMaxPerNodeCount() >= 0, "getMaxPerNodeCount() >= 0", c.getMaxPerNodeCount());
ensure(c.getService() != null, "getService() != null", c.getService());
ensure(c.getTotalCount() > 0 || c.getMaxPerNodeCount() > 0,
"c.getTotalCount() > 0 || c.getMaxPerNodeCount() > 0", null);
}
/**
* Gather system info from all nodes and print it out.
*
* @param ignite Ignite instance.
* @throws IgniteException if failed.
*/
private static void gatherSystemInfo(Ignite ignite) throws IgniteException {
// Gather system info from all nodes.
Collection<String> res = ignite.compute().broadcast(() -> {
System.out.println();
System.out.println("Executing task on node: " + ignite.cluster().localNode().id());
return "Node ID: " + ignite.cluster().localNode().id() + "\n" +
"OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " +
System.getProperty("os.arch") + "\n" +
"User: " + System.getProperty("user.name") + "\n" +
"JRE: " + System.getProperty("java.runtime.name") + " " +
System.getProperty("java.runtime.version");
});
// Print result.
System.out.println();
System.out.println("Nodes system information:");
System.out.println();
res.forEach(r -> {
System.out.println(r);
System.out.println();
});
}
/** @throws Exception If fails. */
@Test
public void testClusterSnapshotInMemoryFail() throws Exception {
persistence = false;
IgniteEx srv = startGrid(0);
srv.cluster().state(ACTIVE);
IgniteEx clnt = startClientGrid(1);
IgniteFuture<?> fut = clnt.snapshot().createSnapshot(SNAPSHOT_NAME);
assertThrowsAnyCause(log,
fut::get,
IgniteException.class,
"Snapshots on an in-memory clusters are not allowed.");
}
/** */
@Ignore("https://issues.apache.org/jira/browse/IGNITE-10723")
@Test
public void testIncompatibleTmLookup() {
final IgniteEx ignite = grid(0);
final CacheConfiguration cacheCfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
cacheCfg.setName("Foo");
cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
cacheCfg.setTransactionManagerLookupClassName(TestTmLookup2.class.getName());
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws IgniteException {
ignite.createCache(cacheCfg);
return null;
}
}, IgniteException.class, null);
}
/**
* Checks removed status after fail.
*
* @param cause Initial exception.
* @return Ignite runtime exception that corresponds the original {@code cause}.
*/
protected IgniteException checkRemovedAfterFail(Exception cause) {
assert cause != null : "The original cause must not be null.";
needCheckNotRemoved();
try {
checkRemoved();
}
catch (Exception e) {
// The original exception should be returned.
}
if (cause instanceof IgniteCheckedException)
return U.convertException((IgniteCheckedException) cause);
else if (cause instanceof EntryProcessorException)
return new IgniteException(cause.getMessage(), cause);
else {
assert cause instanceof IgniteException;
return (IgniteException)cause;
}
}
/** {@inheritDoc} */
@Override protected Collection<? extends ComputeJob> split(int gridSize, String arg) {
try {
JsonNode json = JSON_MAPPER.readTree(arg);
List<String> list = null;
if (json.isArray()) {
list = new ArrayList<>();
for (JsonNode child : json)
list.add(child.asText());
}
return delegate.split(gridSize, list);
}
catch (IOException e) {
throw new IgniteException(e);
}
}
/** {@inheritDoc} */
@Override public int partition(Object key) {
Integer regionId;
if (key instanceof RegionKey)
regionId = ((RegionKey)key).regionId;
else if (key instanceof BinaryObject) {
BinaryObject bo = (BinaryObject)key;
regionId = bo.field("regionId");
}
else
throw new IgniteException("Unsupported key for region aware affinity");
List<Integer> range = REGION_TO_PART_MAP.get(regionId);
Integer cnt = range.get(1);
return U.safeAbs(key.hashCode() % cnt) + range.get(0); // Assign partition in region's range.
}
/**
* Set args to prepared upsert statement.
*
* @param stmt Statement.
* @param newKey Key.
* @param newVal Value.
* @throws SQLException if failed.
*/
private static void setUpsertStatementArgs(PreparedStatement stmt, long newKey, long newVal)
throws SQLException {
switch (stmt.getConnection().getMetaData().getDatabaseProductName()) {
case "H2":
// No-op.
break;
case "Apache Ignite":
// No-op.
break;
case "MySQL":
case "PostgreSQL":
stmt.setLong(3, newVal);
break;
default:
throw new IgniteException("Unexpected database type [databaseProductName=" +
stmt.getConnection().getMetaData().getDatabaseProductName() + ']');
}
stmt.setLong(1, newKey);
stmt.setLong(2, newVal);
}
/**
* Retrieves partitions size.
*
* @return Rows count.
*/
private long cacheSize(CachePeekMode... modes) {
try {
return cacheInfo.cacheContext().cache().localSize(modes);
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
}
/** {@inheritDoc} */
@Override protected Void run(VisorIgfsFormatTaskArg arg) {
try {
ignite.fileSystem(arg.getIgfsName()).clear();
}
catch (IllegalArgumentException iae) {
throw new IgniteException("Failed to format IGFS: " + arg.getIgfsName(), iae);
}
return null;
}
/** {@inheritDoc} */
@Override public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackC) {
GridIoMessage ioMsg = (GridIoMessage)msg;
if (!bannedClasses.contains(ioMsg.message().getClass()))
super.sendMessage(node, msg, ackC);
}
/** {@inheritDoc} */
@Override public IgniteAtomicSequence atomicSequence(String name, AtomicConfiguration cfg, long initVal,
boolean create) throws IgniteException {
throwUnsupported();
return null;
}
/** {@inheritDoc} */
@Override protected Void run(@Nullable VisorScanQueryCancelTaskArg arg) throws IgniteException {
new QueryMXBeanImpl(ignite.context())
.cancelScan(arg.getOriginNodeId(), arg.getCacheName(), arg.getQueryId());
return null;
}
/**
* @throws Exception If failed.
*/
@Test
public void testDynamicCacheStartFromNotExistConfig() throws Exception {
try {
ignite(0).getOrCreateCache(load("config/cache.xml"));
fail();
}
catch (IgniteException ignored) {
// No-op.
}
}
/** {@inheritDoc} */
@Override public <R> R affinityCall(IgniteCallable<R> job) {
if (!collocated)
throw new IgniteException("Failed to execute affinityCall() for non-collocated set: " + name() +
". This operation is supported only for collocated sets.");
return compute.affinityCall(cache.name(), setKey, job);
}