aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-09-25 21:35:39 +0100
committerMelanie2012-09-27 15:25:32 +0100
commit1a902fceb54d9501f489b2ce872a0b03b5b17ad5 (patch)
tree53ad2401c2f901a43278068a096f46a04b6485cb /OpenSim
parentMerge commit '77355295dadaf3be54ac29d6b3d30901e95c0a32' into careminster (diff)
downloadopensim-SC_OLD-1a902fceb54d9501f489b2ce872a0b03b5b17ad5.zip
opensim-SC_OLD-1a902fceb54d9501f489b2ce872a0b03b5b17ad5.tar.gz
opensim-SC_OLD-1a902fceb54d9501f489b2ce872a0b03b5b17ad5.tar.bz2
opensim-SC_OLD-1a902fceb54d9501f489b2ce872a0b03b5b17ad5.tar.xz
Fix occasional race condition failure when creating new clothing/body parts in the viewer or updating existing assets.
On creating these items, the viewer sends a UDP AssetUploadRequest followed by a CreateInventoryItem. It was possible for the CreateInventoryItem/UpdateInventoryItem to occasionally outrace the AssetUploadRequest and fail to find an initialized Xfer object, at which point the item create would fail. So instead we always set up a Xfer object on either the asset or inventory item update request. This does not introduce a new race because code already exists to delay the item operation until the asset is uploaded if necessary (but this only worked if the xfer object already existed)
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs123
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs9
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs71
3 files changed, 93 insertions, 110 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs
index b557ffe..bba7b9c 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs
@@ -57,39 +57,36 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
57 } 57 }
58 58
59 /// <summary> 59 /// <summary>
60 /// Return a xfer uploader if one does not already exist. 60 /// Return the xfer uploader for the given transaction.
61 /// </summary> 61 /// </summary>
62 /// <remarks>
63 /// If an uploader does not already exist for this transaction then it is created, otherwise the existing
64 /// uploader is returned.
65 /// </remarks>
62 /// <param name="transactionID"></param> 66 /// <param name="transactionID"></param>
63 /// <param name="assetID"> 67 /// <returns>The asset xfer uploader</returns>
64 /// We must transfer the new asset ID into the uploader on creation, otherwise 68 public AssetXferUploader RequestXferUploader(UUID transactionID)
65 /// we can see race conditions with other threads which can retrieve an item before it is updated with the new
66 /// asset id.
67 /// </param>
68 /// <returns>
69 /// The xfer uploader requested. Null if one is already in existence.
70 /// FIXME: This is a bizarre thing to do, and is probably meant to signal an error condition if multiple
71 /// transfers are made. Needs to be corrected.
72 /// </returns>
73 public AssetXferUploader RequestXferUploader(UUID transactionID, UUID assetID)
74 { 69 {
70 AssetXferUploader uploader;
71
75 lock (XferUploaders) 72 lock (XferUploaders)
76 { 73 {
77 if (!XferUploaders.ContainsKey(transactionID)) 74 if (!XferUploaders.ContainsKey(transactionID))
78 { 75 {
79 AssetXferUploader uploader = new AssetXferUploader(this, m_Scene, assetID, m_dumpAssetsToFile); 76 uploader = new AssetXferUploader(this, m_Scene, m_dumpAssetsToFile);
80 77
81// m_log.DebugFormat( 78// m_log.DebugFormat(
82// "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID); 79// "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID);
83 80
84 XferUploaders.Add(transactionID, uploader); 81 XferUploaders.Add(transactionID, uploader);
85 82 }
86 return uploader; 83 else
84 {
85 uploader = XferUploaders[transactionID];
87 } 86 }
88 } 87 }
89 88
90 m_log.WarnFormat("[AGENT ASSETS TRANSACTIONS]: Ignoring request for asset xfer uploader {0} since it already exists", transactionID); 89 return uploader;
91
92 return null;
93 } 90 }
94 91
95 public void HandleXfer(ulong xferID, uint packetID, byte[] data) 92 public void HandleXfer(ulong xferID, uint packetID, byte[] data)
@@ -151,23 +148,11 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
151 string description, string name, sbyte invType, 148 string description, string name, sbyte invType,
152 sbyte type, byte wearableType, uint nextOwnerMask) 149 sbyte type, byte wearableType, uint nextOwnerMask)
153 { 150 {
154 AssetXferUploader uploader = null; 151 AssetXferUploader uploader = RequestXferUploader(transactionID);
155 152
156 lock (XferUploaders) 153 uploader.RequestCreateInventoryItem(
157 { 154 remoteClient, transactionID, folderID, callbackID,
158 if (XferUploaders.ContainsKey(transactionID)) 155 description, name, invType, type, wearableType, nextOwnerMask);
159 uploader = XferUploaders[transactionID];
160 }
161
162 if (uploader != null)
163 uploader.RequestCreateInventoryItem(
164 remoteClient, transactionID, folderID,
165 callbackID, description, name, invType, type,
166 wearableType, nextOwnerMask);
167 else
168 m_log.ErrorFormat(
169 "[AGENT ASSET TRANSACTIONS]: Could not find uploader with transaction ID {0} when handling request to create inventory item {1} from {2}",
170 transactionID, name, remoteClient.Name);
171 } 156 }
172 157
173 /// <summary> 158 /// <summary>
@@ -197,69 +182,37 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
197 SceneObjectPart part, UUID transactionID, 182 SceneObjectPart part, UUID transactionID,
198 TaskInventoryItem item) 183 TaskInventoryItem item)
199 { 184 {
200 AssetXferUploader uploader = null; 185 AssetBase asset = GetTransactionAsset(transactionID);
201 186
202 lock (XferUploaders) 187 // Only legacy viewers use this, and they prefer CAPS, which
203 { 188 // we have, so this really never runs.
204 if (XferUploaders.ContainsKey(transactionID)) 189 // Allow it, but only for "safe" types.
205 uploader = XferUploaders[transactionID]; 190 if ((InventoryType)item.InvType != InventoryType.Notecard &&
206 } 191 (InventoryType)item.InvType != InventoryType.LSL)
192 return;
207 193
208 if (uploader != null) 194 if (asset != null)
209 { 195 {
210 AssetBase asset = GetTransactionAsset(transactionID);
211
212 // Only legacy viewers use this, and they prefer CAPS, which
213 // we have, so this really never runs.
214 // Allow it, but only for "safe" types.
215 if ((InventoryType)item.InvType != InventoryType.Notecard &&
216 (InventoryType)item.InvType != InventoryType.LSL)
217 return;
218
219 if (asset != null)
220 {
221// m_log.DebugFormat( 196// m_log.DebugFormat(
222// "[AGENT ASSETS TRANSACTIONS]: Updating item {0} in {1} for transaction {2}", 197// "[AGENT ASSETS TRANSACTIONS]: Updating item {0} in {1} for transaction {2}",
223// item.Name, part.Name, transactionID); 198// item.Name, part.Name, transactionID);
224 199
225 asset.FullID = UUID.Random(); 200 asset.FullID = UUID.Random();
226 asset.Name = item.Name; 201 asset.Name = item.Name;
227 asset.Description = item.Description; 202 asset.Description = item.Description;
228 asset.Type = (sbyte)item.Type; 203 asset.Type = (sbyte)item.Type;
229 item.AssetID = asset.FullID; 204 item.AssetID = asset.FullID;
230 205
231 m_Scene.AssetService.Store(asset); 206 m_Scene.AssetService.Store(asset);
232 }
233 }
234 else
235 {
236 m_log.ErrorFormat(
237 "[AGENT ASSET TRANSACTIONS]: Could not find uploader with transaction ID {0} when handling request to update task inventory item {1} in {2}",
238 transactionID, item.Name, part.Name);
239 } 207 }
240 } 208 }
241 209
242 public void RequestUpdateInventoryItem(IClientAPI remoteClient, 210 public void RequestUpdateInventoryItem(IClientAPI remoteClient,
243 UUID transactionID, InventoryItemBase item) 211 UUID transactionID, InventoryItemBase item)
244 { 212 {
245 AssetXferUploader uploader = null; 213 AssetXferUploader uploader = RequestXferUploader(transactionID);
246
247 lock (XferUploaders)
248 {
249 if (XferUploaders.ContainsKey(transactionID))
250 uploader = XferUploaders[transactionID];
251 }
252 214
253 if (uploader != null) 215 uploader.RequestUpdateInventoryItem(remoteClient, transactionID, item);
254 {
255 uploader.RequestUpdateInventoryItem(remoteClient, transactionID, item);
256 }
257 else
258 {
259 m_log.ErrorFormat(
260 "[AGENT ASSET TRANSACTIONS]: Could not find uploader with transaction ID {0} when handling request to update inventory item {1} for {2}",
261 transactionID, item.Name, remoteClient.Name);
262 }
263 } 216 }
264 } 217 }
265} 218} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
index 7081989..10a0794 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
@@ -274,13 +274,8 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
274 } 274 }
275 275
276 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); 276 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
277 AssetXferUploader uploader = transactions.RequestXferUploader(transaction, assetID); 277 AssetXferUploader uploader = transactions.RequestXferUploader(transaction);
278 278 uploader.StartUpload(remoteClient, assetID, transaction, type, data, storeLocal, tempFile);
279 if (uploader != null)
280 {
281 uploader.Initialise(remoteClient, assetID, transaction, type,
282 data, storeLocal, tempFile);
283 }
284 } 279 }
285 280
286 /// <summary> 281 /// <summary>
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
index 4cedfe6..d134c43 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
@@ -49,11 +49,26 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 50
51 /// <summary> 51 /// <summary>
52 /// Upload state.
53 /// </summary>
54 /// <remarks>
55 /// New -> Uploading -> Complete
56 /// </remarks>
57 private enum UploadState
58 {
59 New,
60 Uploading,
61 Complete
62 }
63
64 /// <summary>
52 /// Reference to the object that holds this uploader. Used to remove ourselves from it's list if we 65 /// Reference to the object that holds this uploader. Used to remove ourselves from it's list if we
53 /// are performing a delayed update. 66 /// are performing a delayed update.
54 /// </summary> 67 /// </summary>
55 AgentAssetTransactions m_transactions; 68 AgentAssetTransactions m_transactions;
56 69
70 private UploadState m_uploadState = UploadState.New;
71
57 private AssetBase m_asset; 72 private AssetBase m_asset;
58 private UUID InventFolder = UUID.Zero; 73 private UUID InventFolder = UUID.Zero;
59 private sbyte invType = 0; 74 private sbyte invType = 0;
@@ -65,7 +80,6 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
65 80
66 private string m_description = String.Empty; 81 private string m_description = String.Empty;
67 private bool m_dumpAssetToFile; 82 private bool m_dumpAssetToFile;
68 private bool m_finished = false;
69 private string m_name = String.Empty; 83 private string m_name = String.Empty;
70 private bool m_storeLocal; 84 private bool m_storeLocal;
71 private uint nextPerm = 0; 85 private uint nextPerm = 0;
@@ -77,11 +91,10 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
77 public ulong XferID; 91 public ulong XferID;
78 private Scene m_Scene; 92 private Scene m_Scene;
79 93
80 public AssetXferUploader(AgentAssetTransactions transactions, Scene scene, UUID assetID, bool dumpAssetToFile) 94 public AssetXferUploader(AgentAssetTransactions transactions, Scene scene, bool dumpAssetToFile)
81 { 95 {
82 m_transactions = transactions; 96 m_transactions = transactions;
83 m_Scene = scene; 97 m_Scene = scene;
84 m_asset = new AssetBase() { FullID = assetID };
85 m_dumpAssetToFile = dumpAssetToFile; 98 m_dumpAssetToFile = dumpAssetToFile;
86 } 99 }
87 100
@@ -127,20 +140,43 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
127 } 140 }
128 141
129 /// <summary> 142 /// <summary>
130 /// Initialise asset transfer from the client 143 /// Start asset transfer from the client
131 /// </summary> 144 /// </summary>
132 /// <param name="xferID"></param> 145 /// <param name="remoteClient"></param>
133 /// <param name="packetID"></param> 146 /// <param name="assetID"></param>
134 /// <param name="data"></param> 147 /// <param name="transaction"></param>
135 public void Initialise(IClientAPI remoteClient, UUID assetID, 148 /// <param name="type"></param>
136 UUID transaction, sbyte type, byte[] data, bool storeLocal, 149 /// <param name="data">
137 bool tempFile) 150 /// Optional data. If present then the asset is created immediately with this data
151 /// rather than requesting an upload from the client. The data must be longer than 2 bytes.
152 /// </param>
153 /// <param name="storeLocal"></param>
154 /// <param name="tempFile"></param>
155 public void StartUpload(
156 IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type, byte[] data, bool storeLocal,
157 bool tempFile)
138 { 158 {
139// m_log.DebugFormat( 159// m_log.DebugFormat(
140// "[ASSET XFER UPLOADER]: Initialised xfer from {0}, asset {1}, transaction {2}, type {3}, storeLocal {4}, tempFile {5}, already received data length {6}", 160// "[ASSET XFER UPLOADER]: Initialised xfer from {0}, asset {1}, transaction {2}, type {3}, storeLocal {4}, tempFile {5}, already received data length {6}",
141// remoteClient.Name, assetID, transaction, type, storeLocal, tempFile, data.Length); 161// remoteClient.Name, assetID, transaction, type, storeLocal, tempFile, data.Length);
142 162
163 lock (this)
164 {
165 if (m_uploadState != UploadState.New)
166 {
167 m_log.WarnFormat(
168 "[ASSET XFER UPLOADER]: Tried to start upload of asset {0}, transaction {1} for {2} but this is already in state {3}. Aborting.",
169 assetID, transaction, remoteClient.Name, m_uploadState);
170
171 return;
172 }
173
174 m_uploadState = UploadState.Uploading;
175 }
176
143 ourClient = remoteClient; 177 ourClient = remoteClient;
178
179 m_asset = new AssetBase() { FullID = assetID };
144 m_asset.Name = "blank"; 180 m_asset.Name = "blank";
145 m_asset.Description = "empty"; 181 m_asset.Description = "empty";
146 m_asset.Type = type; 182 m_asset.Type = type;
@@ -175,14 +211,14 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
175 211
176 protected void SendCompleteMessage() 212 protected void SendCompleteMessage()
177 { 213 {
178 ourClient.SendAssetUploadCompleteMessage(m_asset.Type, true,
179 m_asset.FullID);
180
181 // We must lock in order to avoid a race with a separate thread dealing with an inventory item or create 214 // We must lock in order to avoid a race with a separate thread dealing with an inventory item or create
182 // message from other client UDP. 215 // message from other client UDP.
183 lock (this) 216 lock (this)
184 { 217 {
185 m_finished = true; 218 m_uploadState = UploadState.Complete;
219
220 ourClient.SendAssetUploadCompleteMessage(m_asset.Type, true, m_asset.FullID);
221
186 if (m_createItem) 222 if (m_createItem)
187 { 223 {
188 DoCreateItem(m_createItemCallback); 224 DoCreateItem(m_createItemCallback);
@@ -252,7 +288,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
252 // We must lock to avoid a race with a separate thread uploading the asset. 288 // We must lock to avoid a race with a separate thread uploading the asset.
253 lock (this) 289 lock (this)
254 { 290 {
255 if (m_finished) 291 if (m_uploadState == UploadState.Complete)
256 { 292 {
257 DoCreateItem(callbackID); 293 DoCreateItem(callbackID);
258 } 294 }
@@ -280,7 +316,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
280 item.AssetID = m_asset.FullID; 316 item.AssetID = m_asset.FullID;
281 m_Scene.InventoryService.UpdateItem(item); 317 m_Scene.InventoryService.UpdateItem(item);
282 318
283 if (m_finished) 319 if (m_uploadState == UploadState.Complete)
284 { 320 {
285 StoreAssetForItemUpdate(item); 321 StoreAssetForItemUpdate(item);
286 } 322 }
@@ -416,7 +452,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
416 /// <returns>null if the asset has not finished uploading</returns> 452 /// <returns>null if the asset has not finished uploading</returns>
417 public AssetBase GetAssetData() 453 public AssetBase GetAssetData()
418 { 454 {
419 if (m_finished) 455 if (m_uploadState == UploadState.Complete)
420 { 456 {
421 ValidateAssets(); 457 ValidateAssets();
422 return m_asset; 458 return m_asset;
@@ -469,4 +505,3 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
469 } 505 }
470 } 506 }
471} 507}
472