1
Description: Fixes Walrus OOM errors.
2
Origin: Manually generated from diff of Ubuntu 1.6.2 branch and upstream
3
Bug: https://launchpad.net/bugs/565101
4
--- a/clc/modules/walrus/src/main/java/edu/ucsb/eucalyptus/cloud/ws/WalrusManager.java
5
+++ b/clc/modules/walrus/src/main/java/edu/ucsb/eucalyptus/cloud/ws/WalrusManager.java
9
while ((dataMessage = putQueue.take())!=null) {
10
+ if(putQueue.getInterrupted()) {
12
+ if(WalrusDataMessage.isEOF(dataMessage)) {
13
+ WalrusMonitor monitor = messenger.getMonitor(key);
14
+ if(monitor.getLastModified() == null) {
15
+ synchronized (monitor) {
19
+ lastModified = monitor.getLastModified();
20
+ md5 = monitor.getMd5();
21
+ //ok we are done here
24
+ ObjectDeleter objectDeleter = new ObjectDeleter(bucketName, tempObjectName, -1L);
25
+ objectDeleter.start();
26
+ LOG.info("Transfer interrupted: "+ key);
27
+ messenger.removeQueue(key, randomKey);
32
if(WalrusDataMessage.isStart(dataMessage)) {
33
tempObjectName = objectName + "." + Hashes.getRandom(12);
34
digest = Hashes.Digest.MD5.get();
37
} else if(WalrusDataMessage.isEOF(dataMessage)) {
39
- WalrusMonitor monitor = messenger.getMonitor(key);
40
- synchronized (monitor) {
44
- storageManager.renameObject(bucketName, tempObjectName, objectName);
45
- } catch (IOException ex) {
47
- messenger.removeQueue(key, randomKey);
48
- messenger.removeMonitor(key);
49
- throw new EucalyptusCloudException(objectKey);
53
+ storageManager.renameObject(bucketName, tempObjectName, objectName);
54
+ } catch (IOException ex) {
56
+ messenger.removeQueue(key, randomKey);
57
+ throw new EucalyptusCloudException(objectKey);
60
+ md5 = Hashes.bytesToHex(digest.digest());
61
+ lastModified = new Date();
62
+ long oldObjectSize = 0L;
63
+ dbObject = WalrusControl.getEntityWrapper();
64
+ searchObject = new ObjectInfo(bucketName, objectKey);
65
+ ObjectInfo foundObject;
67
+ foundObject = dbObject.getUnique(searchObject);
68
+ if (foundObject.canWriteACP(userId)) {
69
+ List<GrantInfo> grantInfos = new ArrayList<GrantInfo>();
70
+ foundObject.addGrants(userId, grantInfos,
72
+ foundObject.setGrants(grantInfos);
75
- md5 = Hashes.bytesToHex(digest.digest());
76
- lastModified = new Date();
77
- long oldObjectSize = 0L;
78
- dbObject = WalrusControl.getEntityWrapper();
79
- searchObject = new ObjectInfo(bucketName, objectKey);
80
- ObjectInfo foundObject;
82
- foundObject = dbObject.getUnique(searchObject);
83
- if (foundObject.canWriteACP(userId)) {
84
- List<GrantInfo> grantInfos = new ArrayList<GrantInfo>();
85
- foundObject.addGrants(userId, grantInfos,
87
- foundObject.setGrants(grantInfos);
89
- oldObjectSize = foundObject.getSize();
90
- if(WalrusProperties.enableTorrents) {
91
- EntityWrapper<TorrentInfo> dbTorrent = db.recast(TorrentInfo.class);
92
- TorrentInfo torrentInfo = new TorrentInfo(bucketName, objectKey);
93
- List<TorrentInfo> torrentInfos = dbTorrent.query(torrentInfo);
94
- if(torrentInfos.size() > 0) {
95
- TorrentInfo foundTorrentInfo = torrentInfos.get(0);
96
- TorrentClient torrentClient = Torrents.getClient(bucketName + objectKey);
97
- if(torrentClient != null) {
98
- torrentClient.bye();
100
- dbTorrent.delete(foundTorrentInfo);
101
+ oldObjectSize = foundObject.getSize();
102
+ if(WalrusProperties.enableTorrents) {
103
+ EntityWrapper<TorrentInfo> dbTorrent = db.recast(TorrentInfo.class);
104
+ TorrentInfo torrentInfo = new TorrentInfo(bucketName, objectKey);
105
+ List<TorrentInfo> torrentInfos = dbTorrent.query(torrentInfo);
106
+ if(torrentInfos.size() > 0) {
107
+ TorrentInfo foundTorrentInfo = torrentInfos.get(0);
108
+ TorrentClient torrentClient = Torrents.getClient(bucketName + objectKey);
109
+ if(torrentClient != null) {
110
+ torrentClient.bye();
113
- LOG.warn("Bittorrent support has been disabled. Please check pre-requisites");
115
- } catch (EucalyptusCloudException ex) {
116
- if(objectInfo != null) {
117
- foundObject = objectInfo;
119
- messenger.removeMonitor(key);
120
- messenger.removeQueue(key, randomKey);
122
- throw new EucalyptusCloudException("Unable to update object: " + bucketName + "/" + objectKey);
123
+ dbTorrent.delete(foundTorrentInfo);
126
+ LOG.warn("Bittorrent support has been disabled. Please check pre-requisites");
128
- foundObject.setEtag(md5);
129
- foundObject.replaceMetaData(request.getMetaData());
130
- foundObject.setSize(size);
131
- foundObject.setLastModified(lastModified);
132
- foundObject.setStorageClass("STANDARD");
133
- foundObject.setContentType(request.getContentType());
134
- foundObject.setContentDisposition(request.getContentDisposition());
135
- reply.setSize(size);
136
- if(WalrusProperties.shouldEnforceUsageLimits && !request.isAdministrator()) {
137
- Long bucketSize = bucket.getBucketSize();
138
- long newSize = bucketSize - oldObjectSize + size;
139
- if(newSize > WalrusProperties.MAX_BUCKET_SIZE) {
140
- messenger.removeQueue(key, randomKey);
141
- messenger.removeMonitor(key);
142
- dbObject.rollback();
143
- throw new EntityTooLargeException("Key", objectKey);
145
- bucket.setBucketSize(newSize);
147
- if(WalrusProperties.trackUsageStatistics) {
148
- walrusStatistics.updateBytesIn(size);
149
- walrusStatistics.updateSpaceUsed(size);
150
+ } catch (EucalyptusCloudException ex) {
151
+ if(objectInfo != null) {
152
+ foundObject = objectInfo;
155
+ throw new EucalyptusCloudException("Unable to update object: " + bucketName + "/" + objectKey);
157
- if(logData != null) {
158
- logData.setObjectSize(size);
159
- updateLogData(bucket, logData);
161
+ foundObject.setEtag(md5);
162
+ foundObject.replaceMetaData(request.getMetaData());
163
+ foundObject.setSize(size);
164
+ foundObject.setLastModified(lastModified);
165
+ foundObject.setStorageClass("STANDARD");
166
+ foundObject.setContentType(request.getContentType());
167
+ foundObject.setContentDisposition(request.getContentDisposition());
168
+ reply.setSize(size);
169
+ if(WalrusProperties.shouldEnforceUsageLimits && !request.isAdministrator()) {
170
+ Long bucketSize = bucket.getBucketSize();
171
+ long newSize = bucketSize - oldObjectSize + size;
172
+ if(newSize > WalrusProperties.MAX_BUCKET_SIZE) {
173
+ messenger.removeQueue(key, randomKey);
174
+ dbObject.rollback();
175
+ throw new EntityTooLargeException("Key", objectKey);
177
- if(objectInfo != null)
178
- dbObject.add(foundObject);
180
+ bucket.setBucketSize(newSize);
182
- messenger.removeQueue(key, randomKey);
183
- messenger.removeMonitor(key);
184
+ if(WalrusProperties.trackUsageStatistics) {
185
+ walrusStatistics.updateBytesIn(size);
186
+ walrusStatistics.updateSpaceUsed(size);
188
+ if(logData != null) {
189
+ logData.setObjectSize(size);
190
+ updateLogData(bucket, logData);
192
+ if(objectInfo != null)
193
+ dbObject.add(foundObject);
195
if(logData != null) {
196
logData.setTurnAroundTime(Long.parseLong(new String(dataMessage.getPayload())));
199
+ //restart all interrupted puts
200
+ WalrusMonitor monitor = messenger.getMonitor(key);
201
+ synchronized (monitor) {
202
+ monitor.setLastModified(lastModified);
203
+ monitor.setMd5(md5);
204
+ monitor.notifyAll();
206
+ messenger.removeQueue(key, randomKey);
207
LOG.info("Transfer complete: " + key);