yandex-qatools / postgresql-embedded

Embedded PostgreSQL Server
Other
493 stars 90 forks source link

Make sure postgres can work with two different versions (refs #90) #91

Closed smecsia closed 7 years ago

smecsia commented 7 years ago

rebuild this please

BorzdeG commented 7 years ago

I created the PR #92 - fixed an error

smecsia commented 7 years ago

@BorzdeG Thanks for your contributions. But please take a look at the change. This test performs successfuly without any changes to the code.
Your PR #92 actually does not fix anything - there is no necessity to separate directories by version, every database instance creates its own temporary directory (or you can provide your own easily).

BorzdeG commented 7 years ago

I created a TestMultipleInstance.java test class for usage examples. And it is executed successfully without these changes in the code only by 1/3 - only testRunTwoInstanceAtOne

smecsia commented 7 years ago

@BorzdeG ok. thank you! I'll take a look.

BorzdeG commented 7 years ago

@smecsia, I'll try to explain the essence of the problem. Class SubdirTempDir is static on the process and unpacking PostgreSQL Server occurs in the same directory, relative to SubdirTempDir.tempDir. And this entails the fact that different versions of the server can not exist simultaneously in the same Java process.

One could fix unpacking in PostgresFilesToExtract, changing the "root" directory for the outputFile from the archive with pgsql to some temporary one, but this would lead to duplicates of unpacked distributions in case of repeated server starts. So I took the path of least resistance and changed PostgresFilesToExtract.extractBasePath to a path specifying the version of the server distribution. Of course, this resulted in redundancy in the path to the executable file in the form of nested directories, but this is not critical and this solved the problem.

I also slightly optimized the calculation of PostgresFilesToExtract.extractBasePath, taking it beyond the unpacking cycle of the archive.

[russian text] попробую пояснить суть проблемы. класс SubdirTempDir является статичным на процесс и распаковка PostgreSQL Server происходит в один и тот же, относительно SubdirTempDir.tempDir, каталог. А это влечёт за собой то, что разные версии сервера не могут существовать одновременно в том же процессе Java.

Можно было бы поправить распаковку в PostgresFilesToExtract, подменив для outputFile "корневой" каталог из архива с pgsql на какой-нибудь временный, но это бы привело к появлению дубликатов распакованных дистрибутивов в случае повторных запусков сервера. Поэтому я пошёл по пути наименьшего сопротивления и подменил PostgresFilesToExtract.extractBasePath на путь с указанием версии дистрибутива сервера. Конечно, это привело к избыточности в пути до исполняемого файла в виде вложенности каталогов, но это не критично и это решило проблему.

Так же я слегка оптимизировал вычисление PostgresFilesToExtract.extractBasePath, вынеся его за пределы цикла распаковки архива.

smecsia commented 7 years ago

@BorzdeG Right. Now I see the source of the mentioned problem. Thanks for the detailed explanation.