com.gemstone.gemfire.internal.cache.tier.sockets.command.PutAll75 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-core Show documentation
Show all versions of gemfire-core Show documentation
SnappyData store based off Pivotal GemFireXD
The newest version!
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* 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. See accompanying
* LICENSE file.
*/
/**
* Author: Gester Zhou
*/
package com.gemstone.gemfire.internal.cache.tier.sockets.command;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.LinkedHashMap;
import java.util.Map;
import com.gemstone.gemfire.cache.DynamicRegionFactory;
import com.gemstone.gemfire.cache.RegionDestroyedException;
import com.gemstone.gemfire.cache.ResourceException;
import com.gemstone.gemfire.cache.client.internal.PutAllOp;
import com.gemstone.gemfire.cache.operations.PutAllOperationContext;
import com.gemstone.gemfire.distributed.internal.DistributionStats;
import com.gemstone.gemfire.internal.cache.CachedDeserializableFactory;
import com.gemstone.gemfire.internal.cache.EventID;
import com.gemstone.gemfire.internal.cache.LocalRegion;
import com.gemstone.gemfire.internal.cache.PartitionedRegion;
import com.gemstone.gemfire.internal.cache.PutAllPartialResultException;
import com.gemstone.gemfire.internal.cache.Token;
import com.gemstone.gemfire.internal.cache.ha.ThreadIdentifier;
import com.gemstone.gemfire.internal.cache.tier.CachedRegionHelper;
import com.gemstone.gemfire.internal.cache.tier.Command;
import com.gemstone.gemfire.internal.cache.tier.MessageType;
import com.gemstone.gemfire.internal.cache.tier.sockets.BaseCommand;
import com.gemstone.gemfire.internal.cache.tier.sockets.CacheServerStats;
import com.gemstone.gemfire.internal.cache.tier.sockets.ChunkedMessage;
import com.gemstone.gemfire.internal.cache.tier.sockets.Message;
import com.gemstone.gemfire.internal.cache.tier.sockets.Part;
import com.gemstone.gemfire.internal.cache.tier.sockets.ServerConnection;
import com.gemstone.gemfire.internal.cache.tier.sockets.VersionedObjectList;
import com.gemstone.gemfire.internal.cache.versions.VersionTag;
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
import com.gemstone.gemfire.internal.security.AuthorizeRequest;
import com.gemstone.gemfire.internal.util.Breadcrumbs;
public class PutAll75 extends BaseCommand {
private final static PutAll75 singleton = new PutAll75();
public static Command getCommand() {
return singleton;
}
private PutAll75() {
}
@Override
public void cmdExecute(Message msg, ServerConnection servConn, long startp)
throws IOException, InterruptedException {
long start = startp; // copy this since we need to modify it
Part regionNamePart = null, numberOfKeysPart = null, keyPart = null, valuePart = null;
String regionName = null;
int numberOfKeys = 0;
Object key = null;
Part eventPart = null;
boolean replyWithMetaData = false;
VersionedObjectList response = null;
StringBuffer errMessage = new StringBuffer();
CachedRegionHelper crHelper = servConn.getCachedRegionHelper();
CacheServerStats stats = servConn.getCacheServerStats();
if (crHelper.emulateSlowServer() > 0) {
// this.logger.fine("SlowServer", new Exception());
boolean interrupted = Thread.interrupted();
try {
Thread.sleep(crHelper.emulateSlowServer());
}
catch (InterruptedException ugh) {
interrupted = true;
servConn.getCachedRegionHelper().getCache().getCancelCriterion()
.checkCancelInProgress(ugh);
}
finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
// requiresResponse = true;
servConn.setAsTrue(REQUIRES_RESPONSE);
servConn.setAsTrue(REQUIRES_CHUNKED_RESPONSE); // new in 7.5
{
long oldStart = start;
start = DistributionStats.getStatTime();
stats.incReadPutAllRequestTime(start - oldStart);
}
try {
// Retrieve the data from the message parts
// part 0: region name
regionNamePart = msg.getPart(0);
regionName = regionNamePart.getString();
if (regionName == null) {
String putAllMsg = LocalizedStrings.PutAll_THE_INPUT_REGION_NAME_FOR_THE_PUTALL_REQUEST_IS_NULL.toLocalizedString();
logger.warning(LocalizedStrings.TWO_ARG_COLON, new Object[] {servConn.getName(), putAllMsg});
errMessage.append(putAllMsg);
writeChunkedErrorResponse(msg, MessageType.PUT_DATA_ERROR,
errMessage.toString(), servConn);
servConn.setAsTrue(RESPONDED);
return;
}
LocalRegion region = (LocalRegion)crHelper.getRegion(regionName);
if (region == null) {
String reason = " was not found during put request";
writeRegionDestroyedEx(msg, regionName, reason, servConn);
servConn.setAsTrue(RESPONDED);
return;
}
// part 1: eventID
eventPart = msg.getPart(1);
ByteBuffer eventIdPartsBuffer = ByteBuffer.wrap(eventPart
.getSerializedForm());
long threadId = EventID
.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
long sequenceId = EventID
.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
EventID eventId = new EventID(servConn.getEventMemberIDByteArray(),
threadId, sequenceId);
Breadcrumbs.setEventId(eventId);
// part 2: invoke callbacks (used by import)
Part callbacksPart = msg.getPart(2);
boolean skipCallbacks = callbacksPart.getInt() == 1 ? true : false;
// part 3: flags
int flags = msg.getPart(3).getInt();
boolean clientIsEmpty = (flags & PutAllOp.FLAG_EMPTY) != 0;
boolean clientHasCCEnabled = (flags & PutAllOp.FLAG_CONCURRENCY_CHECKS) != 0;
// part 4: number of keys
numberOfKeysPart = msg.getPart(4);
numberOfKeys = numberOfKeysPart.getInt();
if (logger.fineEnabled()) {
StringBuilder buffer = new StringBuilder();
buffer
.append(servConn.getName())
.append(": Received putAll75 request from ")
.append(servConn.getSocketString())
.append(" for region ")
.append(regionName)
.append(" with ")
.append(numberOfKeys)
.append(" entries.");
logger.fine(buffer.toString());
}
// building the map
Map map = new LinkedHashMap();
Map