/** * @param updateSeq Update sequence. * @return {@code True} if entry has been transitioned to state EVICTED. */ boolean tryEvict(boolean updateSeq) { if (state.getReference() != RENTING || state.getStamp() != 0 || groupReserved()) return false; // Attempt to evict partition entries from cache. clearAll(); if (map.isEmpty() && state.compareAndSet(RENTING, EVICTED, 0, 0)) { if (log.isDebugEnabled()) log.debug("Evicted partition: " + this); if (!GridQueryProcessor.isEnabled(cctx.config())) clearSwap(); if (cctx.isDrEnabled()) cctx.dr().partitionEvicted(id); cctx.dataStructures().onPartitionEvicted(id); rent.onDone(); ((GridDhtPreloader) cctx.preloader()).onPartitionEvicted(this, updateSeq); clearDeferredDeletes(); return true; } return false; }
/** * @param updateSeq Update sequence. * @return Future for evict attempt. */ IgniteInternalFuture<Boolean> tryEvictAsync(boolean updateSeq) { if (map.isEmpty() && !GridQueryProcessor.isEnabled(cctx.config()) && state.compareAndSet(RENTING, EVICTED, 0, 0)) { if (log.isDebugEnabled()) log.debug("Evicted partition: " + this); clearSwap(); if (cctx.isDrEnabled()) cctx.dr().partitionEvicted(id); cctx.dataStructures().onPartitionEvicted(id); rent.onDone(); ((GridDhtPreloader) cctx.preloader()).onPartitionEvicted(this, updateSeq); clearDeferredDeletes(); return new GridFinishedFuture<>(true); } return cctx.closures() .callLocalSafe( new GPC<Boolean>() { @Override public Boolean call() { return tryEvict(true); } }, /*system pool*/ true); }
/** * @param updateSeq Update sequence. * @return Future to signal that this node is no longer an owner or backup. */ IgniteInternalFuture<?> rent(boolean updateSeq) { while (true) { int reservations = state.getStamp(); GridDhtPartitionState s = state.getReference(); if (s == RENTING || s == EVICTED) return rent; if (state.compareAndSet(s, RENTING, reservations, reservations)) { if (log.isDebugEnabled()) log.debug("Moved partition to RENTING state: " + this); // Evict asynchronously, as the 'rent' method may be called // from within write locks on local partition. tryEvictAsync(updateSeq); break; } } return rent; }
/** @return {@code True} if transitioned to OWNING state. */ boolean own() { while (true) { int reservations = state.getStamp(); GridDhtPartitionState s = state.getReference(); if (s == RENTING || s == EVICTED) return false; if (s == OWNING) return true; assert s == MOVING; if (state.compareAndSet(MOVING, OWNING, reservations, reservations)) { if (log.isDebugEnabled()) log.debug("Owned partition: " + this); // No need to keep history any more. evictHist = null; return true; } } }
/** {@inheritDoc} */ @SuppressWarnings("ErrorNotRethrown") @Override public IpcEndpoint accept() throws IgniteCheckedException { while (!Thread.currentThread().isInterrupted()) { Socket sock = null; boolean accepted = false; try { sock = srvSock.accept(); accepted = true; InputStream inputStream = sock.getInputStream(); ObjectInputStream in = new ObjectInputStream(inputStream); ObjectOutputStream out = new ObjectOutputStream(sock.getOutputStream()); IpcSharedMemorySpace inSpace = null; IpcSharedMemorySpace outSpace = null; boolean err = true; try { IpcSharedMemoryInitRequest req = (IpcSharedMemoryInitRequest) in.readObject(); if (log.isDebugEnabled()) log.debug("Processing request: " + req); IgnitePair<String> p = inOutToken(req.pid(), size); String file1 = p.get1(); String file2 = p.get2(); assert file1 != null; assert file2 != null; // Create tokens. new File(file1).createNewFile(); new File(file2).createNewFile(); if (log.isDebugEnabled()) log.debug("Created token files: " + p); inSpace = new IpcSharedMemorySpace(file1, req.pid(), pid, size, true, log); outSpace = new IpcSharedMemorySpace(file2, pid, req.pid(), size, false, log); IpcSharedMemoryClientEndpoint ret = new IpcSharedMemoryClientEndpoint(inSpace, outSpace, log); out.writeObject( new IpcSharedMemoryInitResponse( file2, outSpace.sharedMemoryId(), file1, inSpace.sharedMemoryId(), pid, size)); err = !in.readBoolean(); endpoints.add(ret); return ret; } catch (UnsatisfiedLinkError e) { throw IpcSharedMemoryUtils.linkError(e); } catch (IOException e) { if (log.isDebugEnabled()) log.debug( "Failed to process incoming connection " + "(was connection closed by another party):" + e.getMessage()); } catch (ClassNotFoundException e) { U.error(log, "Failed to process incoming connection.", e); } catch (ClassCastException e) { String msg = "Failed to process incoming connection (most probably, shared memory " + "rest endpoint has been configured by mistake)."; LT.warn(log, null, msg); sendErrorResponse(out, e); } catch (IpcOutOfSystemResourcesException e) { if (!omitOutOfResourcesWarn) LT.warn(log, null, OUT_OF_RESOURCES_MSG); sendErrorResponse(out, e); } catch (IgniteCheckedException e) { LT.error(log, e, "Failed to process incoming shared memory connection."); sendErrorResponse(out, e); } finally { // Exception has been thrown, need to free system resources. if (err) { if (inSpace != null) inSpace.forceClose(); // Safety. if (outSpace != null) outSpace.forceClose(); } } } catch (IOException e) { if (!Thread.currentThread().isInterrupted() && !accepted) throw new IgniteCheckedException("Failed to accept incoming connection.", e); if (!closed) LT.error( log, null, "Failed to process incoming shared memory connection: " + e.getMessage()); } finally { U.closeQuiet(sock); } } // while throw new IgniteInterruptedCheckedException("Socket accept was interrupted."); }