Skip to content

Iris에서 go-redis 관련 오류시 fall back 로직 추가 #1735

Open
@goathoon

Description

Describe the problem and solution

문제가 되는 코드는 아래와 같습니다.
Redis자체에서(go-redis 라이브러리 포함) 오류가 생길 경우, 빈 TestCase를 받아오고 return해버려서, go-redis 오픈소스에서 문제가 생기면 채점 요청이 이뤄지지 못합니다. 이를 개선하기 위한 작업이 필요합니다.

++ 추가로, AWS ElastiCache에 문제가 생길 경우에 fallback로직도 마련할 필요가 있을것 같습니다.

func (t *testcaseManager) GetTestcase(problemId string) (Testcase, error) {
	isExist, err := t.cache.IsExist(problemId)
	if err != nil {
		return Testcase{}, fmt.Errorf("GetTestcase: %w", err)
	}

	if !isExist {
		bytes, err := t.source.Get(problemId)
		if err != nil {
			return Testcase{}, fmt.Errorf("get testcase: %w", err)
		}

		elements := []Element{}
		err = json.Unmarshal(bytes, &elements) // validate
		if err != nil {
			return Testcase{}, fmt.Errorf("invalid testcase data: %w", err)
		}

		testcase := Testcase{Elements: elements}
		err = t.cache.Set(problemId, testcase)
		if err != nil {
			return Testcase{}, fmt.Errorf("cache set: %w", err)
		}

		return testcase, nil
	}

	data, err := t.cache.Get(problemId)
	if err != nil {
		return Testcase{}, fmt.Errorf("testcase: %s: %w", problemId, err)
	}

	testcase := Testcase{}
	err = testcase.UnmarshalBinary(data)
	if err != nil {
		return Testcase{}, fmt.Errorf("testcase: %w", err)
	}
	return testcase, nil
}

Validations

Metadata

Assignees

Labels

p2-nice-to-have 🚦Priority 2: 기존 동작에 영향은 없지만, 추가되면 좋을 것⛳️ team-iris

Type

No type

Projects

  • Status

    Pending ✋

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions