From 5b4761e4e59122345c2d758b281240ffdb017f37 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Tue, 18 Jun 2019 23:34:16 +0300 Subject: [PATCH 1/3] Fixes #9. Start GC loop for in-memory textures cache. --- CHANGELOG.md | 5 ++++- api/mojang/queue/in_memory_textures_storage.go | 5 ++++- api/mojang/queue/in_memory_textures_storage_test.go | 2 -- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2484c82..1f10c6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [Unreleased] - xxxx-xx-xx + +### Fixed +- GC for in-memory textures cache has not been initialized. ## [4.2.1] - 2019-05-06 ### Changed diff --git a/api/mojang/queue/in_memory_textures_storage.go b/api/mojang/queue/in_memory_textures_storage.go index 1b8bc00..31c9294 100644 --- a/api/mojang/queue/in_memory_textures_storage.go +++ b/api/mojang/queue/in_memory_textures_storage.go @@ -25,9 +25,12 @@ type inMemoryTexturesStorage struct { } func CreateInMemoryTexturesStorage() *inMemoryTexturesStorage { - return &inMemoryTexturesStorage{ + storage := &inMemoryTexturesStorage{ data: make(map[string]*inMemoryItem), } + storage.Start() + + return storage } func (s *inMemoryTexturesStorage) Start() { diff --git a/api/mojang/queue/in_memory_textures_storage_test.go b/api/mojang/queue/in_memory_textures_storage_test.go index 1e90812..019da74 100644 --- a/api/mojang/queue/in_memory_textures_storage_test.go +++ b/api/mojang/queue/in_memory_textures_storage_test.go @@ -178,8 +178,6 @@ func TestInMemoryTexturesStorage_GarbageCollection(t *testing.T) { storage.StoreTextures("dead24f9a4fa4877b7b04c8c6c72bb46", textures1) storage.StoreTextures("b5d58475007d4f9e9ddd1403e2497579", textures2) - storage.Start() - time.Sleep(inMemoryStorageGCPeriod + time.Millisecond) // Let it start first iteration _, textures1Err := storage.GetTextures("dead24f9a4fa4877b7b04c8c6c72bb46") From f872fe46984e677b075e135eeac30299ab725a63 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 19 Jun 2019 00:56:09 +0300 Subject: [PATCH 2/3] Fix race condition, introduced in the previous commit --- api/mojang/queue/in_memory_textures_storage.go | 1 - api/mojang/queue/in_memory_textures_storage_test.go | 2 ++ cmd/serve.go | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/api/mojang/queue/in_memory_textures_storage.go b/api/mojang/queue/in_memory_textures_storage.go index 31c9294..cb7d8a3 100644 --- a/api/mojang/queue/in_memory_textures_storage.go +++ b/api/mojang/queue/in_memory_textures_storage.go @@ -28,7 +28,6 @@ func CreateInMemoryTexturesStorage() *inMemoryTexturesStorage { storage := &inMemoryTexturesStorage{ data: make(map[string]*inMemoryItem), } - storage.Start() return storage } diff --git a/api/mojang/queue/in_memory_textures_storage_test.go b/api/mojang/queue/in_memory_textures_storage_test.go index 019da74..1e90812 100644 --- a/api/mojang/queue/in_memory_textures_storage_test.go +++ b/api/mojang/queue/in_memory_textures_storage_test.go @@ -178,6 +178,8 @@ func TestInMemoryTexturesStorage_GarbageCollection(t *testing.T) { storage.StoreTextures("dead24f9a4fa4877b7b04c8c6c72bb46", textures1) storage.StoreTextures("b5d58475007d4f9e9ddd1403e2497579", textures2) + storage.Start() + time.Sleep(inMemoryStorageGCPeriod + time.Millisecond) // Let it start first iteration _, textures1Err := storage.GetTextures("dead24f9a4fa4877b7b04c8c6c72bb46") diff --git a/cmd/serve.go b/cmd/serve.go index bc72be8..c0c7bf9 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -51,11 +51,13 @@ var serveCmd = &cobra.Command{ return } + texturesStorage := queue.CreateInMemoryTexturesStorage() + texturesStorage.Start() mojangTexturesQueue := &queue.JobsQueue{ Logger: logger, Storage: &queue.SplittedStorage{ UuidsStorage: mojangUuidsRepository, - TexturesStorage: queue.CreateInMemoryTexturesStorage(), + TexturesStorage: texturesStorage, }, } logger.Info("Mojang's textures queue is successfully initialized") From 0cfed45b64196b7d786b338c768efd017c9334db Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 19 Jun 2019 01:02:41 +0300 Subject: [PATCH 3/3] Prepare 4.2.2 release --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f10c6e..8b9a8c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - xxxx-xx-xx +## [4.2.2] - 2019-06-19 ### Fixed - GC for in-memory textures cache has not been initialized. @@ -60,6 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 from the textures link instead. - `hash` field from `POST /api/skins` endpoint. -[Unreleased]: https://github.com/elyby/chrly/compare/4.2.1...HEAD +[Unreleased]: https://github.com/elyby/chrly/compare/4.2.2...HEAD +[4.2.2]: https://github.com/elyby/chrly/compare/4.2.1...4.2.2 [4.2.1]: https://github.com/elyby/chrly/compare/4.2.0...4.2.1 [4.2.0]: https://github.com/elyby/chrly/compare/4.1.1...4.2.0