use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class GridDeploymentClassLoader method sendClassRequest.
/**
* Sends class-loading request to all nodes associated with this class loader.
*
* @param name Class name.
* @param path Class path.
* @return Class byte source.
* @throws ClassNotFoundException If class was not found.
*/
private GridByteArrayList sendClassRequest(String name, String path) throws ClassNotFoundException {
assert !Thread.holdsLock(mux);
long endTime = computeEndTime(p2pTimeout);
Collection<UUID> nodeListCp;
Map<UUID, IgniteUuid> nodeLdrMapCp;
synchronized (mux) {
// Skip requests for the previously missed classes.
if (missedRsrcs != null && missedRsrcs.contains(path))
throw new ClassNotFoundException("Failed to peer load class [class=" + name + ", nodeClsLdrIds=" + nodeLdrMap + ", parentClsLoader=" + getParent() + ']');
// If single-node mode, then node cannot change and we simply reuse list and map.
// Otherwise, make copies that can be used outside synchronization.
nodeListCp = singleNode ? nodeList : new LinkedList<>(nodeList);
nodeLdrMapCp = singleNode ? nodeLdrMap : new HashMap<>(nodeLdrMap);
}
IgniteCheckedException err = null;
for (UUID nodeId : nodeListCp) {
if (nodeId.equals(ctx.discovery().localNode().id()))
// Skip local node as it is already used as parent class loader.
continue;
IgniteUuid ldrId = nodeLdrMapCp.get(nodeId);
ClusterNode node = ctx.discovery().node(nodeId);
if (node == null) {
if (log.isDebugEnabled())
log.debug("Found inactive node in class loader (will skip): " + nodeId);
continue;
}
try {
GridDeploymentResponse res = comm.sendResourceRequest(path, ldrId, node, endTime);
if (res == null) {
String msg = "Failed to send class-loading request to node (is node alive?) [node=" + node.id() + ", clsName=" + name + ", clsPath=" + path + ", clsLdrId=" + ldrId + ", parentClsLdr=" + getParent() + ']';
if (!quiet)
U.warn(log, msg);
else if (log.isDebugEnabled())
log.debug(msg);
err = new IgniteCheckedException(msg);
continue;
}
if (res.success())
return res.byteSource();
// In case of shared resources/classes all nodes should have it.
if (log.isDebugEnabled())
log.debug("Failed to find class on remote node [class=" + name + ", nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", reason=" + res.errorMessage() + ']');
synchronized (mux) {
if (missedRsrcs != null)
missedRsrcs.add(path);
}
throw new ClassNotFoundException("Failed to peer load class [class=" + name + ", nodeClsLdrs=" + nodeLdrMapCp + ", parentClsLoader=" + getParent() + ", reason=" + res.errorMessage() + ']');
} catch (IgniteCheckedException e) {
// by processing cancellation request.
if (Thread.currentThread().isInterrupted()) {
if (!quiet)
U.error(log, "Failed to find class probably due to task/job cancellation: " + name, e);
else if (log.isDebugEnabled())
log.debug("Failed to find class probably due to task/job cancellation [name=" + name + ", err=" + e + ']');
} else {
if (!quiet)
U.warn(log, "Failed to send class-loading request to node (is node alive?) [node=" + node.id() + ", clsName=" + name + ", clsPath=" + path + ", clsLdrId=" + ldrId + ", parentClsLdr=" + getParent() + ", err=" + e + ']');
else if (log.isDebugEnabled())
log.debug("Failed to send class-loading request to node (is node alive?) [node=" + node.id() + ", clsName=" + name + ", clsPath=" + path + ", clsLdrId=" + ldrId + ", parentClsLdr=" + getParent() + ", err=" + e + ']');
err = e;
}
}
}
throw new ClassNotFoundException("Failed to peer load class [class=" + name + ", nodeClsLdrs=" + nodeLdrMapCp + ", parentClsLoader=" + getParent() + ']', err);
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class GridDeploymentPerVersionStore method createNewDeployment.
/**
* Creates and caches new deployment.
*
* @param meta Deployment metadata.
* @param isCache Whether or not to cache.
* @return New deployment.
*/
private SharedDeployment createNewDeployment(GridDeploymentMetadata meta, boolean isCache) {
assert Thread.holdsLock(mux);
assert meta.parentLoader() == null;
IgniteUuid ldrId = IgniteUuid.fromUuid(ctx.localNodeId());
GridDeploymentClassLoader clsLdr;
if (meta.deploymentMode() == CONTINUOUS || meta.participants() == null) {
// Create peer class loader.
// Note that we are passing empty list for local P2P exclude, as it really
// does not make sense with shared deployment.
clsLdr = new GridDeploymentClassLoader(ldrId, meta.userVersion(), meta.deploymentMode(), false, ctx, ctx.config().getClassLoader() != null ? ctx.config().getClassLoader() : U.gridClassLoader(), meta.classLoaderId(), meta.senderNodeId(), comm, ctx.config().getNetworkTimeout(), log, ctx.config().getPeerClassLoadingLocalClassPathExclude(), ctx.config().getPeerClassLoadingMissedResourcesCacheSize(), meta.deploymentMode() == CONTINUOUS, /* enable class byte cache in CONTINUOUS mode */
false);
if (meta.participants() != null)
for (Map.Entry<UUID, IgniteUuid> e : meta.participants().entrySet()) clsLdr.register(e.getKey(), e.getValue());
if (log.isDebugEnabled())
log.debug("Created class loader in CONTINUOUS mode or without participants " + "[ldr=" + clsLdr + ", meta=" + meta + ']');
} else {
assert meta.deploymentMode() == SHARED;
// Create peer class loader.
// Note that we are passing empty list for local P2P exclude, as it really
// does not make sense with shared deployment.
clsLdr = new GridDeploymentClassLoader(ldrId, meta.userVersion(), meta.deploymentMode(), false, ctx, U.gridClassLoader(), meta.participants(), comm, ctx.config().getNetworkTimeout(), log, ctx.config().getPeerClassLoadingLocalClassPathExclude(), ctx.config().getPeerClassLoadingMissedResourcesCacheSize(), false, false);
if (log.isDebugEnabled())
log.debug("Created classloader in SHARED mode with participants " + "[ldr=" + clsLdr + ", meta=" + meta + ']');
}
// Give this deployment a unique class loader to emphasize that this
// ID is unique to this shared deployment and is not ID of loader on
// sender node.
SharedDeployment dep = new SharedDeployment(meta.deploymentMode(), clsLdr, ldrId, meta.userVersion(), meta.alias());
if (log.isDebugEnabled())
log.debug("Created new deployment: " + dep);
if (isCache) {
List<SharedDeployment> deps = F.addIfAbsent(cache, meta.userVersion(), new LinkedList<SharedDeployment>());
assert deps != null;
deps.add(dep);
if (log.isDebugEnabled())
log.debug("Added deployment to cache: " + cache);
}
return dep;
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class GridDeploymentPerVersionStore method getDeployment.
/** {@inheritDoc} */
@Override
@Nullable
public GridDeployment getDeployment(GridDeploymentMetadata meta) {
assert meta != null;
assert ctx.config().isPeerClassLoadingEnabled();
// Validate metadata.
assert meta.classLoaderId() != null;
assert meta.senderNodeId() != null;
assert meta.sequenceNumber() >= -1;
assert meta.parentLoader() == null;
if (log.isDebugEnabled())
log.debug("Starting to peer-load class based on deployment metadata: " + meta);
if (meta.participants() == null && !checkLoadRemoteClass(meta.className(), meta)) {
if (log.isDebugEnabled())
log.debug("Skipping deployment check as remote node does not have required class: " + meta);
return null;
}
while (true) {
List<SharedDeployment> depsToCheck = null;
SharedDeployment dep = null;
synchronized (mux) {
// Check obsolete request.
if (isDeadClassLoader(meta))
return null;
if (meta.participants() != null && !meta.participants().isEmpty()) {
Map<UUID, IgniteUuid> participants = new LinkedHashMap<>();
for (Map.Entry<UUID, IgniteUuid> e : meta.participants().entrySet()) {
// Warn if local node is in participants.
if (ctx.localNodeId().equals(e.getKey())) {
// Warn only if mode is not CONTINUOUS.
if (meta.deploymentMode() != CONTINUOUS)
LT.warn(log, "Local node is in participants (most probably, " + "IgniteConfiguration.getPeerClassLoadingLocalClassPathExclude() " + "is not used properly " + "[locNodeId=" + ctx.localNodeId() + ", meta=" + meta + ']');
continue;
}
// Skip left nodes.
if (ctx.discovery().node(e.getKey()) != null)
participants.put(e.getKey(), e.getValue());
}
if (!participants.isEmpty()) {
// Set new participants.
meta = new GridDeploymentMetadata(meta);
meta.participants(participants);
if (log.isDebugEnabled())
log.debug("Created new meta with updated participants: " + meta);
} else {
if (log.isDebugEnabled())
log.debug("All participants has gone: " + meta);
// can have this classes deployed.
if (meta.deploymentMode() != CONTINUOUS)
return null;
}
} else if (ctx.discovery().node(meta.senderNodeId()) == null) {
if (log.isDebugEnabled())
log.debug("Sender node has gone: " + meta);
return null;
}
List<SharedDeployment> deps = cache.get(meta.userVersion());
if (deps != null) {
assert !deps.isEmpty();
for (SharedDeployment d : deps) {
if (d.hasParticipant(meta.senderNodeId(), meta.classLoaderId()) || meta.senderNodeId().equals(ctx.localNodeId())) {
// Done.
dep = d;
break;
}
}
if (dep == null) {
checkRedeploy(meta);
// whether they should be reused for this request.
for (SharedDeployment d : deps) {
if (!d.pendingUndeploy() && !d.undeployed()) {
Map<UUID, IgniteUuid> parties = d.participants();
if (parties != null) {
IgniteUuid ldrId = parties.get(meta.senderNodeId());
if (ldrId != null) {
assert !ldrId.equals(meta.classLoaderId());
if (log.isDebugEnabled())
log.debug("Skipping deployment (loaders on remote node are different) " + "[dep=" + d + ", meta=" + meta + ']');
continue;
}
}
if (depsToCheck == null)
depsToCheck = new LinkedList<>();
if (log.isDebugEnabled())
log.debug("Adding deployment to check: " + d);
depsToCheck.add(d);
}
}
// If no deployment can be reused, create a new one.
if (depsToCheck == null) {
dep = createNewDeployment(meta, false);
deps.add(dep);
}
}
} else {
checkRedeploy(meta);
// Create peer class loader.
dep = createNewDeployment(meta, true);
}
}
if (dep != null) {
if (log.isDebugEnabled())
log.debug("Found SHARED or CONTINUOUS deployment after first check: " + dep);
// Cache the deployed class.
Class<?> cls = dep.deployedClass(meta.className(), meta.alias());
if (cls == null) {
U.warn(log, "Failed to load peer class (ignore if class got undeployed during preloading) [alias=" + meta.alias() + ", dep=" + dep + ']');
return null;
}
return dep;
}
assert meta.parentLoader() == null;
assert depsToCheck != null;
assert !depsToCheck.isEmpty();
// In most cases this loop will find something.
for (SharedDeployment d : depsToCheck) {
// Load class. Note, that remote node will not load this class.
// The class will only be loaded on this node.
Class<?> cls = d.deployedClass(meta.className(), meta.alias());
if (cls != null) {
synchronized (mux) {
if (!d.undeployed() && !d.pendingUndeploy()) {
if (!addParticipant(d, meta))
return null;
if (log.isDebugEnabled())
log.debug("Acquired deployment after verifying it's availability on " + "existing nodes [depCls=" + cls + ", dep=" + d + ", meta=" + meta + ']');
return d;
}
}
} else if (log.isDebugEnabled()) {
log.debug("Deployment cannot be reused (class does not exist on participating nodes) [dep=" + d + ", meta=" + meta + ']');
}
}
// or the class indeed should have a separate deployment.
for (SharedDeployment d : depsToCheck) {
// deployment.
if (meta.participants() != null || checkLoadRemoteClass(d.sampleClassName(), meta)) {
synchronized (mux) {
if (d.undeployed() || d.pendingUndeploy())
continue;
// to load the class from the latest node.
if (!addParticipant(d, meta)) {
if (log.isDebugEnabled())
log.debug("Failed to add participant to deployment " + "[meta=" + meta + ", dep=" + dep + ']');
return null;
}
}
Class<?> depCls = d.deployedClass(meta.className(), meta.alias());
if (depCls == null) {
U.error(log, "Failed to peer load class after loading it as a resource [alias=" + meta.alias() + ", dep=" + dep + ']');
return null;
}
if (log.isDebugEnabled())
log.debug("Acquired deployment class after verifying other class " + "availability on sender node [depCls=" + depCls + ", rndCls=" + d.sampleClassName() + ", sampleClsName=" + d.sampleClassName() + ", meta=" + meta + ']');
return d;
} else if (log.isDebugEnabled())
log.debug("Deployment cannot be reused (random class could not be loaded from sender node) [dep=" + d + ", meta=" + meta + ']');
}
synchronized (mux) {
if (log.isDebugEnabled())
log.debug("None of the existing class-loaders fits (will try to create a new one): " + meta);
// Check obsolete request.
if (isDeadClassLoader(meta))
return null;
// Check that deployment picture has not changed.
List<SharedDeployment> deps = cache.get(meta.userVersion());
if (deps != null) {
assert !deps.isEmpty();
boolean retry = false;
for (SharedDeployment d : deps) {
// Double check if sender was already added.
if (d.hasParticipant(meta.senderNodeId(), meta.classLoaderId())) {
dep = d;
retry = false;
break;
}
// Need to recheck it again.
if (!d.pendingUndeploy() && !d.undeployed() && !depsToCheck.contains(d))
retry = true;
}
if (retry) {
if (log.isDebugEnabled())
log.debug("Retrying due to concurrency issues: " + meta);
// Outer while loop.
continue;
}
if (dep == null) {
// No new deployments were added, so we can safely add ours.
dep = createNewDeployment(meta, false);
deps.add(dep);
if (log.isDebugEnabled())
log.debug("Adding new deployment within second check [dep=" + dep + ", meta=" + meta + ']');
}
} else {
dep = createNewDeployment(meta, true);
if (log.isDebugEnabled())
log.debug("Created new deployment within second check [dep=" + dep + ", meta=" + meta + ']');
}
}
if (dep != null) {
// Cache the deployed class.
Class<?> cls = dep.deployedClass(meta.className(), meta.alias());
if (cls == null) {
U.warn(log, "Failed to load peer class (ignore if class got undeployed during preloading) [alias=" + meta.alias() + ", dep=" + dep + ']');
return null;
}
}
return dep;
}
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class GridDeploymentClassLoader method sendResourceRequest.
/**
* Sends resource request to all remote nodes associated with this class loader.
*
* @param name Resource name.
* @return InputStream for resource or {@code null} if resource could not be found.
*/
@Nullable
private InputStream sendResourceRequest(String name) {
assert !Thread.holdsLock(mux);
long endTime = computeEndTime(p2pTimeout);
Collection<UUID> nodeListCp;
Map<UUID, IgniteUuid> nodeLdrMapCp;
synchronized (mux) {
// Skip requests for the previously missed classes.
if (missedRsrcs != null && missedRsrcs.contains(name))
return null;
// If single-node mode, then node cannot change and we simply reuse list and map.
// Otherwise, make copies that can be used outside synchronization.
nodeListCp = singleNode ? nodeList : new LinkedList<>(nodeList);
nodeLdrMapCp = singleNode ? nodeLdrMap : new HashMap<>(nodeLdrMap);
}
for (UUID nodeId : nodeListCp) {
if (nodeId.equals(ctx.discovery().localNode().id()))
// Skip local node as it is already used as parent class loader.
continue;
IgniteUuid ldrId = nodeLdrMapCp.get(nodeId);
ClusterNode node = ctx.discovery().node(nodeId);
if (node == null) {
if (log.isDebugEnabled())
log.debug("Found inactive node in class loader (will skip): " + nodeId);
continue;
}
try {
// Request is sent with timeout that is why we can use synchronization here.
GridDeploymentResponse res = comm.sendResourceRequest(name, ldrId, node, endTime);
if (res == null) {
U.warn(log, "Failed to get resource from node (is node alive?) [nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", resName=" + name + ", parentClsLdr=" + getParent() + ']');
} else if (!res.success()) {
synchronized (mux) {
// Cache unsuccessfully loaded resource.
if (missedRsrcs != null)
missedRsrcs.add(name);
}
// resources. So we print out INFO level message.
if (!quiet) {
if (log.isInfoEnabled())
log.info("Failed to get resource from node [nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", resName=" + name + ", parentClsLdr=" + getParent() + ", msg=" + res.errorMessage() + ']');
} else if (log.isDebugEnabled())
log.debug("Failed to get resource from node [nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", resName=" + name + ", parentClsLdr=" + getParent() + ", msg=" + res.errorMessage() + ']');
// Do not ask other nodes in case of shared mode all of them should have the resource.
return null;
} else {
return new ByteArrayInputStream(res.byteSource().internalArray(), 0, res.byteSource().size());
}
} catch (IgniteCheckedException e) {
// by processing cancellation request.
if (Thread.currentThread().isInterrupted()) {
if (!quiet)
U.error(log, "Failed to get resource probably due to task/job cancellation: " + name, e);
else if (log.isDebugEnabled())
log.debug("Failed to get resource probably due to task/job cancellation: " + name);
} else {
if (!quiet)
U.warn(log, "Failed to get resource from node (is node alive?) [nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", resName=" + name + ", parentClsLdr=" + getParent() + ", err=" + e + ']');
else if (log.isDebugEnabled())
log.debug("Failed to get resource from node (is node alive?) [nodeId=" + node.id() + ", clsLdrId=" + ldrId + ", resName=" + name + ", parentClsLdr=" + getParent() + ", err=" + e + ']');
}
}
}
return null;
}
use of org.apache.ignite.lang.IgniteUuid in project ignite by apache.
the class GridUrlConnection method connect.
/** {@inheritDoc} */
@Override
public void connect() throws IOException {
URL url = getURL();
// Gets class loader UUID.
IgniteUuid ldrId = IgniteUuid.fromString(url.getHost());
// Gets resource name.
String name = url.getPath();
GridDeployment dep = mgr.getDeployment(ldrId);
if (dep != null) {
in = dep.classLoader().getParent().getResourceAsStream(name);
// If resource exists
connected = true;
}
}
Aggregations