Skip to content

Instantly share code, notes, and snippets.

View rponte's full-sized avatar
🏠
Working from home

Rafael Ponte rponte

🏠
Working from home
View GitHub Profile
@rponte
rponte / postgresql_serializable_isolation.sql
Created October 25, 2024 15:05 — forked from nathanl/postgresql_serializable_isolation.sql
PostgreSQL Serializable Isolation - false positives
-- (This code was run in PostgreSQL 9.6.1)
-- Demonstration of how serializable isolation for PostgreSQL, which detects possible
-- interference between concurrent transactions, can produce false positives
-- in psql, create the following table
CREATE TABLE users(
id SERIAL NOT NULL PRIMARY KEY,
username VARCHAR NOT NULL
);
@rponte
rponte / partitioning.md
Last active September 2, 2024 23:48
Patitioning: the third pillar of scalability
@rponte
rponte / races-conditions.md
Created September 2, 2024 15:16 — forked from rafaelpontezup/races-conditions.md
Chapter Stackspot: Race conditions, locking e bancos de dados relacionais

Race conditions, locking e bancos de dados relacionais

Pretendo apresentar um código com uma lógica de negócio simples que funciona bem na perspectiva do negócio mas que quebra miseravelmente em ambientes minimamente concorrentes. Para isso, vou demonstrar através de testes de integração como identificar o Race Condition no código e principalmente como resolvê-lo através de mecanismos de locking e Isolation Level do seu banco de dados;

O que vamos discutir

  1. Por que estudamos esse assunto mais a fundo?
  • 1.3. A importância do treino: o que eu levei alguns bons anos para aprender o Jordi levou 6 meses
@rponte
rponte / README.md
Last active January 5, 2024 19:19
StackSpot Action: action responsible for creating a Gitlab repository written in Python

Create Repository Gitlab

Creates a new repository (aka project) in a specific Gitlab group.

How to set up this project

This project was developed with Python v3.9, and it also uses Python's Virtualenv tool. So before working on this project we need to set up it.

Inside this project's folder, execute those commands to configure your environment:

@rponte
rponte / CreateNewUserController.java
Last active January 9, 2024 14:37
Designing fault-tolerant and idempotent APIs with HTTP requests mapped to database's transactions at 1:1 model
/**
* This Spring Boot controller was implemented as an example of a simple but robust idempotent REST API that
* leverages the ACID properties of a relational database.
*/
@RestController
public class CreateNewUserController {
@Autowired
private UserRepository repository;
@Autowired
@rponte
rponte / AccountRepository.java
Last active February 7, 2024 02:36
JPA and Hibernate: Simple and Smart way of using PostgreSQL Advisory Locks with JPQL to prevent Lost Update anomaly
package br.com.stackspot.nullbank.withdrawal;
import org.hibernate.LockOptions;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
import javax.persistence.LockModeType;
import javax.persistence.QueryHint;
import javax.transaction.Transactional;
import java.util.Optional;
@rponte
rponte / BookRepositoryTest.java
Last active January 17, 2024 19:57
Spring Boot: example of base test class for testing Repositories
package br.com.zup.edu.ifoodwebapp.samples.books;
import base.SpringDataJpaIntegrationTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.transaction.TransactionSystemException;
@rponte
rponte / Book.java
Last active May 9, 2024 14:41
AssertJ: Example of a jUnit5 test for asserting Bean Validation errors thrown by Spring Boot Repository
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.ISBN;
import java.util.Objects;
import static org.hibernate.validator.constraints.ISBN.Type.ISBN_13;
@rponte
rponte / how-to-fix.md
Last active July 16, 2024 08:19
Git clone and SSL certificate problem: "unable to get local issuer certificate" and "server certificate verification failed. CAfile: none CRLfile: none"

The issue with SSL certificate

Just out of the blue, I started getting this issue ("server certificate verification failed. CAfile: none CRLfile: none") while trying to clone any Github repository on Linux (WSL2):

git clone https://github.com/rafaelpontezup/preventing-lost-update-racecondition.git
Cloning into 'preventing-lost-update-racecondition'...
fatal: unable to access 'https://github.com/rafaelpontezup/preventing-lost-update-racecondition.git/': server certificate verification failed. CAfile: none CRLfile: none

And also with Window 11 I got "SSL certificate problem: unable to get local issuer certificate":