Skip to content

Commit ce93ff9

Browse files
authored
Merge pull request #20 from tikurahul/main
Fixes #19
2 parents e1b210f + 7c18de7 commit ce93ff9

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

RELEASE-NOTES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Release notes for GCP backed Gradle Remote Cache
2+
3+
## 1.0.0-alpha03
4+
5+
- Fixes issue [19](https://github.com/androidx/gcp-gradle-build-cache/issues/19).
6+
- Remove retry-ing of RPCs.
7+
- When writes fail, we fail silently and treat subsequent reads as a cache-miss.
8+
- Set the `chunkSize` for reads to equal the size of the `Blob`.
9+
This way, we only make 1 RPC per blob input stream. This is safe because
10+
the size of the objects in cache are not very large.

gcpbuildcache/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ gradlePlugin {
5454
}
5555

5656
group = "androidx.build.gradle.gcpbuildcache"
57-
version = "1.0.0-alpha02"
57+
version = "1.0.0-alpha03"
5858

5959
testing {
6060
suites {

gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/GcpStorageService.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ import com.google.api.gax.retrying.RetrySettings
2121
import com.google.auth.oauth2.GoogleCredentials
2222
import com.google.cloud.ReadChannel
2323
import com.google.cloud.http.HttpTransportOptions
24-
import com.google.cloud.storage.BlobId
25-
import com.google.cloud.storage.BlobInfo
26-
import com.google.cloud.storage.StorageOptions
27-
import com.google.cloud.storage.StorageRetryStrategy
24+
import com.google.cloud.storage.*
2825
import org.gradle.api.GradleException
2926
import org.gradle.api.logging.Logging
3027
import java.io.InputStream
@@ -109,14 +106,22 @@ internal class GcpStorageService(
109106
private fun load(storage: StorageOptions?, blobId: BlobId): ReadChannel? {
110107
if (storage == null) return null
111108
val blob = storage.service.get(blobId) ?: return null
112-
return blob.reader()
109+
val reader = blob.reader()
110+
// We don't expect to store objects larger than Int.MAX_VALUE
111+
reader.setChunkSize(blob.size.toInt())
112+
return reader
113113
}
114114

115115
private fun store(storage: StorageOptions?, blobId: BlobId, contents: ByteArray): Boolean {
116116
if (storage == null) return false
117117
val blobInfo = BlobInfo.newBuilder(blobId).build()
118-
storage.service.createFrom(blobInfo, contents.inputStream())
119-
return true
118+
return try {
119+
storage.service.createFrom(blobInfo, contents.inputStream())
120+
true
121+
} catch (storageException: StorageException) {
122+
logger.debug("Unable to store Blob ($blobId)", storageException)
123+
false
124+
}
120125
}
121126

122127
private fun delete(storage: StorageOptions?, blobId: BlobId): Boolean {
@@ -131,8 +136,8 @@ internal class GcpStorageService(
131136
): StorageOptions? {
132137
val credentials = credentials(gcpCredentials, isPushSupported) ?: return null
133138
val retrySettings = RetrySettings.newBuilder()
134-
retrySettings.maxAttempts = 3
135-
retrySettings.retryDelayMultiplier = 2.0
139+
// We don't want retries.
140+
retrySettings.maxAttempts = 0
136141
return StorageOptions.newBuilder().setCredentials(credentials)
137142
.setStorageRetryStrategy(StorageRetryStrategy.getUniformStorageRetryStrategy()).setProjectId(projectId)
138143
.setRetrySettings(retrySettings.build())

0 commit comments

Comments
 (0)